diff --git a/core/modules/menu_link/lib/Drupal/menu_link/Entity/MenuLink.php b/core/modules/menu_link/lib/Drupal/menu_link/Entity/MenuLink.php index a85d901..ba47151 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/Entity/MenuLink.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/Entity/MenuLink.php @@ -371,16 +371,14 @@ public function setRouteObject(Route $route) { */ public function reset() { // To reset the link to its original values, we need to retrieve its - // definition from hook_default_menu_links(). 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 little harm. + // 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. // @todo Decide whether we want to keep the reset functionality. $all_links = menu_get_default_links(); $original = $all_links[$this->machine_name]; - $storage_controller = \Drupal::entityManager()->getStorageController('menu_link'); - $new_link = $storage_controller->create($original); + $new_link = self::buildFromRouterItem($original); // Merge existing menu link's ID and 'has_children' property. foreach (array('mlid', 'has_children') as $key) { $new_link->{$key} = $this->{$key}; @@ -395,7 +393,7 @@ public function reset() { * This function should only be called for link data from * hook_default_menu_links(). */ - public static function preCreate(EntityStorageControllerInterface $storage_controller, array &$item) { + public static function buildFromRouterItem(array $item) { // Suggested items are disabled by default. $item += array( 'type' => MENU_NORMAL_ITEM, @@ -408,6 +406,13 @@ public static function preCreate(EntityStorageControllerInterface $storage_contr // Note, we set this as 'system', so that we can be sure to distinguish all // the menu links generated automatically from entries in {menu_router}. $item['module'] = 'system'; + $item += array( + 'link_title' => $item['title'], + 'link_path' => $item['path'], + 'options' => empty($item['description']) ? array() : array('attributes' => array('title' => $item['description'])), + ); + return \Drupal::entityManager() + ->getStorageController('menu_link')->create($item); } /**