You are here

function _menu_ui_node_save in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/menu_ui/menu_ui.module \_menu_ui_node_save()

Helper function to create or update a menu link for a node.

Parameters

\Drupal\node\NodeInterface $node: Node entity.

array $values: Values for the menu link.

1 call to _menu_ui_node_save()
menu_ui_form_node_form_submit in core/modules/menu_ui/menu_ui.module
Form submission handler for menu item field on the node form.

File

core/modules/menu_ui/menu_ui.module, line 138
Allows administrators to customize the site's navigation menus.

Code

function _menu_ui_node_save(NodeInterface $node, array $values) {

  /** @var \Drupal\menu_link_content\MenuLinkContentInterface $entity */
  if (!empty($values['entity_id'])) {
    $entity = MenuLinkContent::load($values['entity_id']);
  }
  else {

    // Create a new menu_link_content entity.
    $entity = entity_create('menu_link_content', array(
      'link' => [
        'uri' => 'entity:node/' . $node
          ->id(),
      ],
      'langcode' => $node
        ->getUntranslated()
        ->language()
        ->getId(),
    ));
    $entity->enabled->value = 1;
  }
  $entity->title->value = trim($values['title']);
  $entity->description->value = trim($values['description']);
  $entity->menu_name->value = $values['menu_name'];
  $entity->parent->value = $values['parent'];
  $entity->weight->value = isset($values['weight']) ? $values['weight'] : 0;
  $entity
    ->save();
}