Skip to main content
removed "Drupal" from the title; removed tags from the title
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

Create Programmatically create a node programmatically with Menu Link for Drupal 8a menu link

I created a node programmatically like thiswith the following code.

$data = array(
  'type' => 'inception_article',
  'title' => $msg->name,
  'body' => array(
    'value' => $msg->body,
    'format' => 'full_html'
  )
);

$node = Node::create($data);
$node->save();

I would now also like to create the menu link for the just created node and cant seem to, but I cannot figure out how to do that in Drupal 8.

How can I programmatically create a menu link for a node I create?

Create node programmatically with Menu Link for Drupal 8

I created a node programmatically like this

$data = array(
  'type' => 'inception_article',
  'title' => $msg->name,
  'body' => array(
    'value' => $msg->body,
    'format' => 'full_html'
  )
);

$node = Node::create($data);
$node->save();

I would now also like to create the menu link for the just created node and cant seem to figure out how to do that in Drupal 8

Programmatically create a node with a menu link

I created a node programmatically with the following code.

$data = array(
  'type' => 'inception_article',
  'title' => $msg->name,
  'body' => array(
    'value' => $msg->body,
    'format' => 'full_html'
  )
);

$node = Node::create($data);
$node->save();

I would now also like to create the menu link for the node, but I cannot figure out how to do that in Drupal 8.

How can I programmatically create a menu link for a node I create?

Source Link

Create node programmatically with Menu Link for Drupal 8

I created a node programmatically like this

$data = array(
  'type' => 'inception_article',
  'title' => $msg->name,
  'body' => array(
    'value' => $msg->body,
    'format' => 'full_html'
  )
);

$node = Node::create($data);
$node->save();

I would now also like to create the menu link for the just created node and cant seem to figure out how to do that in Drupal 8