public function MenuLink::reset

Resets a system-defined menu link.

Return value

\Drupal\Core\Entity\EntityInterface A menu link entity.

Overrides MenuLinkInterface::reset

File

drupal/core/modules/menu_link/lib/Drupal/menu_link/Plugin/Core/Entity/MenuLink.php, line 307
Contains \Drupal\menu_link\Plugin\Core\Entity\MenuLink.

Class

MenuLink
Defines the menu link entity class.

Namespace

Drupal\menu_link\Plugin\Core\Entity

Code

public function reset() {

  // To reset the link to its original values, we need to retrieve its
  // definition from hook_menu(). Otherwise, for example, the link's menu
  // would not be reset, because properties like the original 'menu_name' are
  // not stored anywhere else. Since resetting a link happens rarely and this
  // is a one-time operation, retrieving the full menu router does no harm.
  $menu = menu_get_router();
  $router_item = $menu[$this->router_path];
  $new_link = self::buildFromRouterItem($router_item);

  // Merge existing menu link's ID and 'has_children' property.
  foreach (array(
    'mlid',
    'has_children',
  ) as $key) {
    $new_link->{$key} = $this->{$key};
  }
  $new_link
    ->save();
  return $new_link;
}