Programatically untick generate automatic URL alias for new node I am creating a new node and then adding a new menu link. I have the code to correctly add the new node and menu link (below).

$node = Node::create([
              'type' =&gt; 'standard_page',
              'langcode' =&gt; 'en',
              'created' =&gt; REQUEST_TIME,
              'changed' =&gt; REQUEST_TIME,
              'uid' =&gt; 1,
              'title' =&gt; 'new_node',
              'body' =&gt; [
                'summary' =&gt; 'new_node',
                'value' =&gt; 'new_node',
                'format' =&gt; 'full_html',
              ]
          ]);

  $node-&gt;save();

$source = '/node/' . $node-&gt;get('nid')-&gt;value;  \Drupal::service('path.alias_storage')-&gt;save($source, '/new_node', 'en');

$link = MenuLinkContent::create([
      'title'      =&gt; $title,
      'link'       =&gt; ['uri' =&gt; 'internal:/new_node'],
      'menu_name'  =&gt; 'main',
      'weight'     =&gt; 10,
    ]);


The problem is that when I go to edit the node, "generate automatic url alias" is always ticked. So whenever I go to update the node, it destroys the alias that I have already created.

I have tried the following code.

$node-&gt;path['pathauto'] = FALSE;  
$node-&gt;save();


This doesn't seem to work in Drupal 8 as I get the following error:


  InvalidArgumentException: Unable to set a value with a non-numeric delta in a list. in Drupal\Core\TypedData\Plugin\DataType\ItemList->set() (line 112 of core\lib\Drupal\Core\TypedData\Plugin\DataType\ItemList.php).


Hoe do I programatically untick the "Generate automatic URL alias" option in Drupal 8?
Save your node twice, once to generate the alias and the second time to turn off that option for the node.

 // Save node to generate alias
 $node-&gt;save();
 // Turn off pathauto
 $node-&gt;path-&gt;pathauto = 0;
 // Save again.
 $node-&gt;save();


Then open edit form and " Generate automatic URL alias" will be unchecked.