diff --git a/core/includes/menu.inc b/core/includes/menu.inc index 0ca3b65..17c65c1 100644 --- a/core/includes/menu.inc +++ b/core/includes/menu.inc @@ -153,8 +153,8 @@ * - weight: Lower (negative) numbers come before higher (positive) numbers, * for menu items with the same parent. * - * Menu items from other modules can be altered using - * hook_menu_link_defaults_alter(). + * Discovered menu links from other modules can be altered using + * hook_menu_links_discovered_alter(). * * @todo Derivatives will probably be defined for these; when they are, add * documentation here. diff --git a/core/lib/Drupal/Core/EventSubscriber/MenuRouterRebuildSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/MenuRouterRebuildSubscriber.php index ba2cc7b..4b0b41f 100644 --- a/core/lib/Drupal/Core/EventSubscriber/MenuRouterRebuildSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/MenuRouterRebuildSubscriber.php @@ -30,7 +30,7 @@ class MenuRouterRebuildSubscriber implements EventSubscriberInterface { protected $lock; /** - * The menu link plugin manager + * The menu link plugin manager. * * @var \Drupal\Core\Menu\MenuLinkManagerInterface $menuLinkManager */ @@ -96,4 +96,3 @@ static function getSubscribedEvents() { } } - diff --git a/core/lib/Drupal/Core/EventSubscriber/RouterRebuildSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/RouterRebuildSubscriber.php index 69f49e4..584b141 100644 --- a/core/lib/Drupal/Core/EventSubscriber/RouterRebuildSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/RouterRebuildSubscriber.php @@ -11,7 +11,6 @@ use Drupal\Core\Lock\LockBackendInterface; use Drupal\Core\Routing\RouteBuilderInterface; use Drupal\Core\Routing\RoutingEvents; -use Drupal\Core\Menu\MenuLinkManagerInterface; use Symfony\Component\EventDispatcher\Event; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpKernel\Event\PostResponseEvent; diff --git a/core/lib/Drupal/Core/Menu/MenuLinkBase.php b/core/lib/Drupal/Core/Menu/MenuLinkBase.php index 43cb49a..331b26b 100644 --- a/core/lib/Drupal/Core/Menu/MenuLinkBase.php +++ b/core/lib/Drupal/Core/Menu/MenuLinkBase.php @@ -40,18 +40,7 @@ public function getWeight() { /** * {@inheritdoc} */ - public function getTitle() { - // Subclasses may pull in the request or specific attributes as parameters. - $options = array(); - if (!empty($this->pluginDefinition['title_context'])) { - $options['context'] = $this->pluginDefinition['title_context']; - } - $args = array(); - if (isset($this->pluginDefinition['title_arguments']) && $title_arguments = $this->pluginDefinition['title_arguments']) { - $args = (array) $title_arguments; - } - return $this->t($this->pluginDefinition['title'], $args, $options); - } + abstract public function getTitle(); /** * {@inheritdoc} @@ -112,12 +101,7 @@ public function isDeletable() { /** * {@inheritdoc} */ - public function getDescription() { - if ($this->pluginDefinition['description']) { - return $this->t($this->pluginDefinition['description']); - } - return ''; - } + abstract public function getDescription(); /** * {@inheritdoc} @@ -190,6 +174,11 @@ public function getTranslateRoute() { /** * {@inheritdoc} */ + abstract public function updateLink(array $new_definition_values, $persist); + + /** + * {@inheritdoc} + */ public function deleteLink() { throw new PluginException(String::format('Menu link plugin with ID @id does not support deletion', array('@id' => $this->getPluginId()))); } diff --git a/core/lib/Drupal/Core/Menu/MenuLinkDefault.php b/core/lib/Drupal/Core/Menu/MenuLinkDefault.php index f84e0b2..5d0f8e2 100644 --- a/core/lib/Drupal/Core/Menu/MenuLinkDefault.php +++ b/core/lib/Drupal/Core/Menu/MenuLinkDefault.php @@ -66,6 +66,32 @@ public static function create(ContainerInterface $container, array $configuratio /** * {@inheritdoc} */ + public function getTitle() { + // Subclasses may pull in the request or specific attributes as parameters. + $options = array(); + if (!empty($this->pluginDefinition['title_context'])) { + $options['context'] = $this->pluginDefinition['title_context']; + } + $args = array(); + if (isset($this->pluginDefinition['title_arguments']) && $title_arguments = $this->pluginDefinition['title_arguments']) { + $args = (array) $title_arguments; + } + return $this->t($this->pluginDefinition['title'], $args, $options); + } + + /** + * {@inheritdoc} + */ + public function getDescription() { + if ($this->pluginDefinition['description']) { + return $this->t($this->pluginDefinition['description']); + } + return ''; + } + + /** + * {@inheritdoc} + */ public function isResettable() { // The link can be reset if it has an override. return (bool) $this->staticOverride->loadOverride($this->getPluginId()); diff --git a/core/lib/Drupal/Core/Menu/MenuLinkTree.php b/core/lib/Drupal/Core/Menu/MenuLinkTree.php index 943698c..e5d54fe 100644 --- a/core/lib/Drupal/Core/Menu/MenuLinkTree.php +++ b/core/lib/Drupal/Core/Menu/MenuLinkTree.php @@ -63,7 +63,8 @@ class MenuLinkTree implements MenuLinkTreeInterface { /** * Stores the cached current route parameters by menu and current route match. * - * @todo Remove this non-static caching in https://www.drupal.org/node/1805054. + * @todo Remove this non-static caching in + * https://www.drupal.org/node/1805054. * * @var \Drupal\Core\Menu\MenuTreeParameters[] */ diff --git a/core/lib/Drupal/Core/Utility/LinkGenerator.php b/core/lib/Drupal/Core/Utility/LinkGenerator.php index 54a2635..d3093ac 100644 --- a/core/lib/Drupal/Core/Utility/LinkGenerator.php +++ b/core/lib/Drupal/Core/Utility/LinkGenerator.php @@ -101,7 +101,7 @@ public function generateFromUrl($text, Url $url) { // @todo System path is deprecated - use the route name and parameters. $system_path = $url->getInternalPath(); // Special case for the front page. - $variables['options']['attributes']['data-drupal-link-system-path'] = $system_path != '' ?: ''; + $variables['options']['attributes']['data-drupal-link-system-path'] = $system_path == '' ? '' : $system_path; } } diff --git a/core/modules/menu_ui/src/MenuForm.php b/core/modules/menu_ui/src/MenuForm.php index 658986c..91000b5 100644 --- a/core/modules/menu_ui/src/MenuForm.php +++ b/core/modules/menu_ui/src/MenuForm.php @@ -249,7 +249,7 @@ protected function buildOverviewForm(array &$form, array &$form_state) { * Recursive helper function for buildOverviewForm(). * * @param $tree - * The menu_tree retrieved by menu_tree_data. + * The tree retrieved by \Drupal\Core\Menu\MenuLinkTreeInterface::load(). * @param $delta * The default number of menu items used in the menu weight selector is 50. * diff --git a/core/modules/system/src/Tests/Menu/MenuRouterTest.php b/core/modules/system/src/Tests/Menu/MenuRouterTest.php index 406c134..270badc 100644 --- a/core/modules/system/src/Tests/Menu/MenuRouterTest.php +++ b/core/modules/system/src/Tests/Menu/MenuRouterTest.php @@ -52,7 +52,7 @@ public function testMenuIntegration() { $this->doTestMenuOptionalPlaceholders(); $this->doTestMenuOnRoute(); $this->doTestMenuName(); - $this->doTestMenuLinkDefaultsAlter(); + $this->doTestMenuLinksDiscoveredAlter(); $this->doTestHookMenuIntegration(); $this->doTestExoticPath(); } @@ -127,21 +127,21 @@ protected function doTestMenuName() { } /** - * Tests menu links added in hook_menu_link_defaults_alter(). + * Tests menu links added in hook_menu_links_discovered_alter(). */ - protected function doTestMenuLinkDefaultsAlter() { + protected function doTestMenuLinksDiscoveredAlter() { // Check that machine name does not need to be defined since it is already // set as the key of each menu link. /** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */ $menu_link_manager = \Drupal::service('plugin.manager.menu.link'); $menu_links = $menu_link_manager->loadLinksByRoute('menu_test.custom'); $menu_link = reset($menu_links); - $this->assertEqual($menu_link->getPluginId(), 'menu_test.custom', 'Menu links added at hook_menu_link_defaults_alter() obtain the machine name from the $links key.'); + $this->assertEqual($menu_link->getPluginId(), 'menu_test.custom', 'Menu links added at hook_menu_links_discovered_alter() obtain the machine name from the $links key.'); // Make sure that rebuilding the menu tree does not produce duplicates of - // links added by hook_menu_link_defaults_alter(). + // links added by hook_menu_links_discovered_alter(). \Drupal::service('router.builder')->rebuild(); $this->drupalGet('menu-test'); - $this->assertUniqueText('Custom link', 'Menu links added by hook_menu_link_defaults_alter() do not duplicate after a menu rebuild.'); + $this->assertUniqueText('Custom link', 'Menu links added by hook_menu_links_discovered_alter() do not duplicate after a menu rebuild.'); } /** diff --git a/core/modules/views/src/Plugin/Derivative/ViewsMenuLink.php b/core/modules/views/src/Plugin/Derivative/ViewsMenuLink.php index da5007a..e83af2b 100644 --- a/core/modules/views/src/Plugin/Derivative/ViewsMenuLink.php +++ b/core/modules/views/src/Plugin/Derivative/ViewsMenuLink.php @@ -34,7 +34,8 @@ public function getDerivativeDefinition($derivative_id, $base_plugin_definition) */ public function getDerivativeDefinitions($base_plugin_definition) { $links = array(); - // @todo Replaces uses_hook_menu with a different annotation. + // @todo Replace uses_hook_menu with an annotation. + // https://www.drupal.org/node/2310371 $views = Views::getApplicableViews('uses_hook_menu'); foreach ($views as $data) { /** @var \Drupal\views\ViewExecutable $view */ diff --git a/core/modules/views/src/Plugin/Menu/Form/ViewsMenuLinkForm.php b/core/modules/views/src/Plugin/Menu/Form/ViewsMenuLinkForm.php index db8b691..d97b204 100644 --- a/core/modules/views/src/Plugin/Menu/Form/ViewsMenuLinkForm.php +++ b/core/modules/views/src/Plugin/Menu/Form/ViewsMenuLinkForm.php @@ -12,8 +12,8 @@ /** * Provides a form to edit Views menu links. * - * This provides the feature to edit the title, in contrast to the static - * menu link form. + * This provides the feature to edit the title and description, in contrast to + * the default menu link form. * * @see \Drupal\views\Plugin\Menu\ViewsMenuLink */ @@ -35,7 +35,8 @@ public function buildConfigurationForm(array $form, array &$form_state) { $form['title'] = array( '#type' => 'textfield', '#title' => $this->t('Title'), - // @todo how do we ensure that view is not loaded with a translation? + // @todo Ensure that the view is not loaded with a localized title. + // https://www.drupal.org/node/2309507 '#default_value' => $this->menuLink->getTitle(), '#weight' => -10, ); @@ -44,9 +45,9 @@ public function buildConfigurationForm(array $form, array &$form_state) { '#type' => 'textfield', '#title' => $this->t('Description'), '#description' => $this->t('Shown when hovering over the menu link.'), - // @todo how do we ensure that view is not loaded with a translation, - // see https://www.drupal.org/node/2309507 - '#default_value' => $this->menuLink->getTitle(), + // @todo Ensure that the view is not loaded with a localized description. + // https://www.drupal.org/node/2309507 + '#default_value' => $this->menuLink->getDescription(), '#weight' => -5, ); diff --git a/core/modules/views/src/Plugin/Menu/ViewsMenuLink.php b/core/modules/views/src/Plugin/Menu/ViewsMenuLink.php index b7944a6..ff47b54 100644 --- a/core/modules/views/src/Plugin/Menu/ViewsMenuLink.php +++ b/core/modules/views/src/Plugin/Menu/ViewsMenuLink.php @@ -115,8 +115,8 @@ public function loadView() { * {@inheritdoc} */ public function getTitle() { - // @todo - can we get the translated value from the config without - // instantiating the view? + // @todo Get the translated value from the config without instantiating the + // view. https://www.drupal.org/node/2310379 return $this->loadView()->display_handler->getOption('menu')['title']; } @@ -144,8 +144,8 @@ public function updateLink(array $new_definition_values, $persist) { } } if ($changed) { - // @todo Note: This triggers a full rebuild of everything, even we just - // changed some properties.. + // @todo Improve this to not trigger a full rebuild of everything, if we + // just changed some properties. https://www.drupal.org/node/2310389 $view->storage->save(); } } diff --git a/core/tests/Drupal/Tests/Core/Menu/MenuLinkMock.php b/core/tests/Drupal/Tests/Core/Menu/MenuLinkMock.php index 7086aa6..9a9e98e 100644 --- a/core/tests/Drupal/Tests/Core/Menu/MenuLinkMock.php +++ b/core/tests/Drupal/Tests/Core/Menu/MenuLinkMock.php @@ -28,7 +28,6 @@ class MenuLinkMock extends MenuLinkBase { 'options' => array(), 'expanded' => '0', 'hidden' => '0', - 'discovered' => '1', 'provider' => 'simpletest', 'metadata' => array(), 'class' => 'Drupal\\Tests\\Core\Menu\\MenuLinkMock',