diff --git a/core/includes/menu.inc b/core/includes/menu.inc index 85ec6fd..793b53e 100644 --- a/core/includes/menu.inc +++ b/core/includes/menu.inc @@ -759,7 +759,8 @@ function _menu_translate(&$router_item, $map, $to_arg = FALSE) { $router_item['access'] = FALSE; return FALSE; } - // Avoid notices until we remove this code. + // Avoid notices until we remove this function. + // @see https://drupal.org/node/2107533 $tab_root_map = array(); $tab_parent_map = array(); // Generate the link path for the page request or local tasks. @@ -864,8 +865,12 @@ function menu_tail_load($arg, &$map, $index) { * @param $item * A menu link. * + * @return + * Returns the map of path arguments with objects loaded as defined in the + * $item['load_functions']. + * $item['access'] becomes TRUE if the item is accessible, FALSE otherwise. + * $item['href'] is generated from link_path * $item['access'] becomes TRUE if the item is accessible, FALSE otherwise. - * $item['href'] is generated from link_path, or set to NULL for routes. * $item['title'] is generated from link_title. * $item['route_parameters'] is unserialized if needed. * $item['options'] is unserialized and copied to $item['localized_options']. @@ -2383,8 +2388,9 @@ function menu_link_get_preferred($path = NULL, $selected_menu = NULL) { // the menus, ordered by menu preference. $path_candidates = array(); // 1. The current item href. + // @todo simplify this code and convert to using route names. + // @see https://drupal.org/node/2154949 $path_candidates[$path] = $path; - // 2. The tab root href of the current item (if any). // Retrieve a list of menu names, ordered by preference. $menu_names = menu_get_active_menu_names(); @@ -2423,8 +2429,6 @@ function menu_link_get_preferred($path = NULL, $selected_menu = NULL) { } } } - - // @todo How do we fetch the title of tabs and other non menu links. } return isset($preferred_links[$path][$selected_menu]) ? $preferred_links[$path][$selected_menu] : FALSE; @@ -2639,7 +2643,7 @@ function _menu_link_save_recursive($controller, $machine_name, &$children, &$lin _menu_link_save_recursive($controller, $next_name, $children, $links); } } - // Remove process links names so we can find stragglers. + // Remove processed link names so we can find stragglers. unset($children[$machine_name]); } @@ -2671,8 +2675,8 @@ function menu_default_links_rebuild() { $all_links = menu_get_default_links(); if ($all_links) { foreach ($all_links as $machine_name => $link) { - // Note, we set this as 'system', so that we can be sure to distinguish all - // the menu links generated automatically from hook_default_menu_links(). + // Note, we set module as 'system', so that we can distinguish all the + // menu links generated automatically from hook_default_menu_links(). $link['machine_name'] = $machine_name; $link['module'] = 'system'; $link += array( diff --git a/core/modules/config_translation/lib/Drupal/config_translation/Plugin/Derivative/ConfigTranslationContextualLinks.php b/core/modules/config_translation/lib/Drupal/config_translation/Plugin/Derivative/ConfigTranslationContextualLinks.php index 9d06ebd..0fac412 100644 --- a/core/modules/config_translation/lib/Drupal/config_translation/Plugin/Derivative/ConfigTranslationContextualLinks.php +++ b/core/modules/config_translation/lib/Drupal/config_translation/Plugin/Derivative/ConfigTranslationContextualLinks.php @@ -58,7 +58,7 @@ public function getDerivativeDefinitions(array $base_plugin_definition) { continue; } - /** @type \Drupal\config_translation\ConfigMapperInterface $mapper */ + /** @var \Drupal\config_translation\ConfigMapperInterface $mapper */ $route_name = $mapper->getOverviewRouteName(); $this->derivatives[$route_name] = $base_plugin_definition; $this->derivatives[$route_name]['config_translation_plugin_id'] = $plugin_id; diff --git a/core/modules/entity/entity.module b/core/modules/entity/entity.module index e4bd031..d1289c4 100644 --- a/core/modules/entity/entity.module +++ b/core/modules/entity/entity.module @@ -99,7 +99,7 @@ function entity_menu() { * Implements hook_default_menu_links(). */ function entity_default_menu_links() { - $links['admin.structure.display-modes'] = array( + $links['admin.structure.display_modes'] = array( 'link_title' => 'Display modes', 'description' => 'Configure what displays are available for your content and forms.', 'route_name' => 'entity.display_mode', @@ -107,19 +107,19 @@ function entity_default_menu_links() { ); // View modes. - $links['admin.structure.display-modes.view'] = array( + $links['admin.structure.display_modes.view'] = array( 'link_title' => 'View modes', 'description' => 'Manage custom view modes.', 'route_name' => 'entity.view_mode_list', - 'parent' => 'admin.structure.display-modes', + 'parent' => 'admin.structure.display_modes', ); // Form modes. - $links['admin.structure.display-modes.form'] = array( + $links['admin.structure.display_modes.form'] = array( 'link_title' => 'Form modes', 'description' => 'Manage custom form modes.', 'route_name' => 'entity.form_mode_list', - 'parent' => 'admin.structure.display-modes', + 'parent' => 'admin.structure.display_modes', ); return $links; diff --git a/core/modules/menu/lib/Drupal/menu/Form/MenuDeleteForm.php b/core/modules/menu/lib/Drupal/menu/Form/MenuDeleteForm.php index 36fc607..57e45c1 100644 --- a/core/modules/menu/lib/Drupal/menu/Form/MenuDeleteForm.php +++ b/core/modules/menu/lib/Drupal/menu/Form/MenuDeleteForm.php @@ -105,8 +105,8 @@ public function submit(array $form, array &$form_state) { } // Reset all the menu links defined by the system via hook_menu(). - // @todo Convert this to an EFQ once we figure out 'ORDER BY m.number_parts'. - $result = $this->connection->query("SELECT mlid FROM {menu_links} ml INNER JOIN {menu_router} m ON ml.link_path = m.path WHERE ml.menu_name = :menu AND ml.module = 'system' ORDER BY m.number_parts ASC", array(':menu' => $this->entity->id()), array('fetch' => \PDO::FETCH_ASSOC))->fetchCol(); + // @todo Convert this to an EFQ. + $result = $this->connection->query("SELECT mlid FROM {menu_links} WHERE menu_name = :menu AND module = 'system' ORDER BY depth ASC", array(':menu' => $this->entity->id()), array('fetch' => \PDO::FETCH_ASSOC))->fetchCol(); $menu_links = $this->storageController->loadMultiple($result); foreach ($menu_links as $link) { $link->reset(); 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 5fc83ce..fad2b5f 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 @@ -380,10 +380,12 @@ public function reset() { // '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. - // @FIXME Decide whether we want to keep the reset functionality. + // @todo Decide whether we want to keep the reset functionality. $all_links = menu_get_default_links(); $original = $all_links[$this->machine_name]; - $new_link = $this->buildFromOriginalItem($original); + $storage_controller = \Drupal::entityManager()->getStorageController('menu_link'); + static::preCreate($storage_controller, $original); + $new_link = $storage_controller->create($original); // Merge existing menu link's ID and 'has_children' property. foreach (array('mlid', 'has_children') as $key) { $new_link->{$key} = $this->{$key}; @@ -393,9 +395,12 @@ public function reset() { } /** - * Create an entity from a default menu link item. + * {@inheritdoc} + * + * This function should only be called for link data from + * hook_default_menu_links(). */ - protected function buildFromOriginalItem(array $item) { + public static function preCreate(EntityStorageControllerInterface $storage_controller, array &$item) { // Suggested items are disabled by default. $item += array( 'type' => MENU_NORMAL_ITEM, @@ -408,8 +413,6 @@ protected function buildFromOriginalItem(array $item) { // 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'; - return \Drupal::entityManager() - ->getStorageController('menu_link')->create($item); } /** @@ -594,7 +597,7 @@ public static function findRouteNameParameters($link_path) { /** * {@inheritdoc} */ - protected function setParents(MenuLink $parent) { + protected function setParents(MenuLinkInterface $parent) { $i = 1; while ($i < $this->depth) { $p = 'p' . $i++; diff --git a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php index f1bae38..75a431a 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php @@ -32,13 +32,6 @@ class MenuLinkStorageController extends DatabaseStorageController implements Men protected $preventReparenting = FALSE; /** - * Holds an array of router item schema fields. - * - * @var array - */ - protected static $routerItemFields = array(); - - /** * The route provider service. * * @var \Symfony\Cmf\Component\Routing\RouteProviderInterface @@ -63,10 +56,6 @@ public function __construct($entity_type, array $entity_info, Connection $databa parent::__construct($entity_type, $entity_info, $database, $uuid_service); $this->routeProvider = $route_provider; - - if (empty(static::$routerItemFields)) { - static::$routerItemFields = array_diff(drupal_schema_fields_sql('menu_router'), array('weight')); - } } /** @@ -95,17 +84,6 @@ public static function createInstance(ContainerInterface $container, $entity_typ } /** - * Overrides DatabaseStorageController::buildQuery(). - */ - protected function buildQuery($ids, $revision_id = FALSE) { - $query = parent::buildQuery($ids, $revision_id); - // Specify additional fields from the {menu_router} table. - $query->leftJoin('menu_router', 'm', 'base.link_path = m.path'); - $query->fields('m', static::$routerItemFields); - return $query; - } - - /** * Overrides DatabaseStorageController::attachLoad(). * * @todo Don't call parent::attachLoad() at all because we want to be able to @@ -225,32 +203,6 @@ public function getPreventReparenting() { /** * {@inheritdoc} */ - public function loadUpdatedCustomized(array $router_paths) { - $query = parent::buildQuery(NULL); - $query - ->condition(db_or() - ->condition('updated', 1) - ->condition(db_and() - ->condition('link_path', $router_paths, 'NOT IN') - ->condition('external', 0) - ->condition('customized', 1) - ) - ); - $query_result = $query->execute(); - - if (!empty($this->entityInfo['class'])) { - // We provide the necessary arguments for PDO to create objects of the - // specified entity class. - // @see \Drupal\Core\Entity\EntityInterface::__construct() - $query_result->setFetchMode(\PDO::FETCH_CLASS, $this->entityInfo['class'], array(array(), $this->entityType)); - } - - return $query_result->fetchAllAssoc($this->idKey); - } - - /** - * {@inheritdoc} - */ public function loadModuleAdminTasks() { $query = $this->buildQuery(NULL); $query diff --git a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageControllerInterface.php b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageControllerInterface.php index 3fb408f..6fad76d 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageControllerInterface.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageControllerInterface.php @@ -34,20 +34,6 @@ public function setPreventReparenting($value = FALSE); public function getPreventReparenting(); /** - * Loads updated and customized menu links for specific router paths. - * - * Note that this is a low-level method and it doesn't return fully populated - * menu link entities. (e.g. no fields are attached) - * - * @param array $router_paths - * An array of router paths. - * - * @return array - * An array of menu link objects indexed by their ids. - */ - public function loadUpdatedCustomized(array $router_paths); - - /** * Loads system menu link as needed by system_get_module_admin_tasks(). * * @return array diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc index 0fce7e4..b126730 100644 --- a/core/modules/system/system.admin.inc +++ b/core/modules/system/system.admin.inc @@ -9,7 +9,6 @@ use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; /** * Menu callback; displays a listing of all themes. diff --git a/core/modules/system/system.install b/core/modules/system/system.install index dd3e946..c0b429e 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -2293,7 +2293,7 @@ function system_update_8060() { } /** - * Add machine_name column to the menu_links table. + * Add machine_name column to the menu_links table and remove router_path field. */ function system_update_8061() { $spec = array( diff --git a/core/modules/system/tests/modules/menu_test/lib/Drupal/menu_test/Controller/MenuTestController.php b/core/modules/system/tests/modules/menu_test/lib/Drupal/menu_test/Controller/MenuTestController.php index bea2c21..46b2c80 100644 --- a/core/modules/system/tests/modules/menu_test/lib/Drupal/menu_test/Controller/MenuTestController.php +++ b/core/modules/system/tests/modules/menu_test/lib/Drupal/menu_test/Controller/MenuTestController.php @@ -19,6 +19,18 @@ public function menuTestCallback() { return menu_test_callback(); } + + /** + * A title callback method for test routes. + * + * @param array $_title_arguments + * Optional array from the route defaults. + * @param string $_title + * Optional _title string from the route defaults. + * + * @return string + * The route title. + */ public function titleCallback(array $_title_arguments = array(), $_title = '') { $_title_arguments += array('case_number' => '2', 'title' => $_title); return t($_title_arguments['title']) . ' - Case ' . $_title_arguments['case_number'];