diff --git a/core/core.services.yml b/core/core.services.yml index 9f766eb..75ffe15 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -277,7 +277,7 @@ services: arguments: ['@plugin.manager.menu.link_tree'] menu.tree_storage: class: Drupal\Core\Menu\MenuTreeStorage - arguments: ['@database', '@url_generator'] + arguments: ['@database', '@url_generator', 'menu_tree'] public: false # This service is private to plugin.manager.menu.link_tree menu_link.static.overrides: class: Drupal\Core\Menu\StaticMenuLinkOverrides diff --git a/core/lib/Drupal/Core/Menu/Form/MenuLinkDefaultForm.php b/core/lib/Drupal/Core/Menu/Form/MenuLinkDefaultForm.php index 54d3098..16f0b43 100644 --- a/core/lib/Drupal/Core/Menu/Form/MenuLinkDefaultForm.php +++ b/core/lib/Drupal/Core/Menu/Form/MenuLinkDefaultForm.php @@ -61,9 +61,10 @@ public static function create(ContainerInterface $container) { } /** - * Injects the menu link. + * Injects the menu link plugin. * * @param MenuLinkInterface $menu_link + * A menu link plugin instance. */ public function setMenuLinkInstance(MenuLinkInterface $menu_link) { $this->menuLink = $menu_link; @@ -80,7 +81,7 @@ public function buildEditForm(array &$form, array &$form_state) { '#title' => $this->t('This is a module-provided link. The label and path cannot be changed.'), ); $form['path'] = array( - $this->menuLink->build(), + 'link' => $this->menuLink->build(), '#type' => 'item', '#title' => $this->t('Link'), ); @@ -91,7 +92,7 @@ public function buildEditForm(array &$form, array &$form_state) { '#description' => $this->t('Menu links that are not enabled will not be listed in any menu.'), '#default_value' => !$this->menuLink->isHidden(), ); - $form['expanded'] = array( + $form['expanded'] = array( '#type' => 'checkbox', '#title' => t('Show as expanded'), '#description' => $this->t('If selected and this menu link has children, the menu will always appear expanded.'), @@ -107,7 +108,7 @@ public function buildEditForm(array &$form, array &$form_state) { ); $options = $this->menuTree->getParentSelectOptions($this->menuLink->getPluginId()); - $menu_parent = $this->menuLink->getMenuName() . ':' . $this->menuLink->getParent(); + $menu_parent = $this->menuLink->getMenuName() . ':' . $this->menuLink->getParent(); if (!isset($options[$menu_parent])) { // Put it at the top level in the current menu. @@ -159,4 +160,3 @@ public function submitEditForm(array &$form, array &$form_state) { } } - diff --git a/core/lib/Drupal/Core/Menu/MenuLinkTree.php b/core/lib/Drupal/Core/Menu/MenuLinkTree.php index 4613a3a..32eb757 100644 --- a/core/lib/Drupal/Core/Menu/MenuLinkTree.php +++ b/core/lib/Drupal/Core/Menu/MenuLinkTree.php @@ -44,7 +44,7 @@ class MenuLinkTree implements MenuLinkTreeInterface { 'route_name' => '', // Parameters for route variables when generating a link. 'route_parameters' => array(), - // The external URL if this link references one (required if route_name is empty). + // The external URL if this link has one (required if route_name is empty). 'url' => '', // The static title for the menu link. 'title' => '', @@ -223,7 +223,8 @@ class MenuLinkTree implements MenuLinkTreeInterface { * @param \Drupal\Core\Menu\StaticMenuLinkOverridesInterface $overrides * Service providing overrides for static links * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack - * The request object to use for building titles and paths for plugin instances. + * A request object for the controller resolver and finding the preferred + * menu and link for the current page. * @param \Drupal\Core\Routing\RouteProviderInterface $route_provider * The route provider to load routes by name. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler @@ -357,6 +358,7 @@ public function hasDefinition($plugin_id) { * {@inheritdoc} * * @return \Drupal\Core\Menu\MenuLinkInterface + * A menu link instance. */ public function createInstance($plugin_id, array $configuration = array()) { return $this->factory->createInstance($plugin_id, $configuration); @@ -399,7 +401,7 @@ public function loadLinks($menu_name) { * deleting a menu entity, so maybe we should load it and make sure it's * not locked? * - * @param $menu_name + * @param string $menu_name * The name of the menu whose links will be deleted. */ public function deleteLinksInMenu($menu_name) { @@ -420,6 +422,9 @@ public function deleteLinksInMenu($menu_name) { Cache::invalidateTags(array('menu' => $affected_menus)); } + /** + * Helper function to delete a specific instance. + */ protected function deleteInstance(MenuLinkInterface $instance, $persist) { $id = $instance->getPluginId(); if ($instance->isDeletable()) { @@ -509,15 +514,12 @@ public function buildRenderTree($tree) { // Set a class if the link is in the active trail. if ($data['in_active_trail']) { $class[] = 'active-trail'; - //$data['link']['localized_options']['attributes']['class'][] = 'active-trail'; } // Allow menu-specific theme overrides. $element['#theme'] = 'menu_link__' . strtr($link->getMenuName(), '-', '_'); $element['#attributes']['class'] = $class; $element['#title'] = $link->getTitle(); - // @todo Use route name and parameters to generate the link path, unless - // it is external. $element['#url'] = $link->getUrlObject(); $element['#below'] = $data['below'] ? $this->buildRenderTree($data['below']) : array(); $element['#original_link'] = $link; @@ -630,7 +632,7 @@ public function getActiveMenuNames() { /** * {@inheritdoc} */ - function setActiveMenuNames($menu_names = NULL) { + public function setActiveMenuNames(array $menu_names) { if (isset($menu_names) && is_array($menu_names)) { $this->activeMenus = $menu_names; @@ -728,6 +730,7 @@ public function buildPageData($menu_name, $max_depth = NULL, $only_active_trail * Is the current request happening on a 403 subrequest. * * @return array + * An array of tree parameters. */ protected function doBuildPageDataTreeParameters($menu_name, $max_depth, $only_active_trail, $page_is_403) { $tree_parameters = array( @@ -805,7 +808,7 @@ public function buildAllData($menu_name, $id = NULL, $max_depth = NULL) { public function getChildLinks($id, $max_relative_depth = NULL) { $links = array(); $definitions = $this->treeStorage->loadAllChildLinks($id, $max_relative_depth); - foreach($definitions as $id => $definition) { + foreach ($definitions as $id => $definition) { $instance = $this->menuLinkCheckAccess($definition); if ($instance) { $links[$id] = $instance; @@ -827,7 +830,7 @@ public function getParentIds($id) { /** * {@inheritdoc} */ - function getChildIds($id) { + public function getChildIds($id) { if ($this->getDefinition($id, FALSE)) { return $this->treeStorage->getAllChildIds($id); } @@ -879,7 +882,7 @@ public function buildTree($menu_name, array $parameters = array()) { } if (!isset($this->menuTree[$tree_cid])) { - // Rebuild the links which are stored + // Rebuild the links which are stored. $data['tree'] = $this->treeStorage->loadTree($menu_name, $parameters); $data['route_names'] = $this->collectRoutes($data['tree']); // Cache the data, if it is not already in the cache. @@ -940,6 +943,9 @@ protected function treeCheckAccess(&$tree) { $this->sortTree($tree); } + /** + * Helper function that recursively checks access for each item. + */ protected function doTreeCheckAccess(&$tree) { foreach ($tree as $key => $v) { $definition = $tree[$key]['definition']; @@ -991,9 +997,10 @@ protected function sortTree(&$tree) { * The menu link definition. * * @return \Drupal\Core\Menu\MenuLinkInterface|NULL + * A plugin instance or NULL if the current user can not access its route. */ protected function menuLinkCheckAccess(array $definition) { - // url should only be populated for external links. + // 'url' should only be populated for external links. if (!empty($definition['url']) && empty($definition['route_name'])) { $access = TRUE; } @@ -1159,7 +1166,7 @@ public function resetLink($id) { /** * Resets the menu link to its default settings. * - * @param \Drupal\Core\Menu\MenuLinkInterface + * @param \Drupal\Core\Menu\MenuLinkInterface $instance * The menu link which should be reset. * * @return \Drupal\Core\Menu\MenuLinkInterface @@ -1199,6 +1206,7 @@ public function resetDefinitions() { * @param string $id * The menu link plugin ID. * @param array $definition + * Optional new definition for the given plugin ID. */ protected function resetDefinition($id, $definition = NULL) { $this->definitions[$id] = $definition; diff --git a/core/lib/Drupal/Core/Menu/MenuLinkTreeInterface.php b/core/lib/Drupal/Core/Menu/MenuLinkTreeInterface.php index 105a869..a75e284 100644 --- a/core/lib/Drupal/Core/Menu/MenuLinkTreeInterface.php +++ b/core/lib/Drupal/Core/Menu/MenuLinkTreeInterface.php @@ -15,9 +15,7 @@ interface MenuLinkTreeInterface extends PluginManagerInterface { /** - * Trigger discover save, and cleanup of static links - * - * @todo find a better name? + * Trigger discovery, save, and cleanup of static links. */ public function rebuild(); @@ -25,6 +23,7 @@ public function rebuild(); * The maximum depth of tree that is supported. * * @return int + * The maximum depth. */ public function maxDepth(); @@ -39,13 +38,12 @@ public function deleteLinksInMenu($menu_name); /** * Deletes a single link from the menu tree. * - * This should only be called when the link data has already been removed from - * any external storage. This method will not attempt to persist the deletion - * except from the tree storage used by the plugin manager. - * * @param string $id * The menu link plugin ID. * @param bool $persist + * If TRUE, this method will attempt to persist the deletion from any + * external storage by invoking MenuLinkInterface::deleteLink() on + * the plugin that is being deleted. * * @throws \Drupal\Component\Plugin\Exception\PluginException * If the $id is not valid, existing, plugin ID or if the link cannot be @@ -105,14 +103,14 @@ public function buildRenderTree($tree); public function getActiveTrailIds($menu_name); /** - * Gets the active menu for the current page. + * Gets the active menus for the current page. * * The active menu for the page determines the active trail. * - * @return + * @return array * An array of menu machine names, in order of preference. The - * 'system.menu:active_menus_default' config item may be used to assert a menu - * order different from the order of creation, or to prevent a particular menu + * 'system.menu:active_menus_default' config item may be used to set a menu + * order different from the default order, or to prevent a particular menu * from being used at all in the active trail. */ public function getActiveMenuNames(); @@ -125,8 +123,9 @@ public function getActiveMenuNames(); * trail. * * @param array $menu_names + * The menu names to use as active for the current page. */ - public function setActiveMenuNames($menu_names = NULL); + public function setActiveMenuNames(array $menu_names); /** * Gets the data structure for a named menu tree, based on the current page. @@ -200,7 +199,7 @@ public function buildAllData($menu_name, $id = NULL, $max_depth = NULL); * condition key/value pairs; see _menu_build_tree() for the actual query. * * @return array - * A fully built menu tree. + * A fully built and access-checked menu tree. */ public function buildTree($menu_name, array $parameters = array()); @@ -213,6 +212,7 @@ public function buildTree($menu_name, array $parameters = array()); * The maximum depth of child menu links relative to the passed in. * * @return array + * A fully built and access-checked menu subtree. */ public function buildSubtree($id, $max_relative_depth = NULL); @@ -302,7 +302,8 @@ public function createLink($id, array $definition); * subset of the plugin definition. * @param bool $persist * TRUE to also have the link instance itself persist the changed values - * to any additional storage. + * to any additional storage by invoking MenuLinkInterface::updateLink() on + * the plugin that is being updated. * * @return \Drupal\Core\Menu\MenuLinkInterface * The updated menu link instance. @@ -330,12 +331,13 @@ public function resetLink($id); /** * Gets a form instance for editing a menu link plugin. * - * @TODO Use the class resolver at some point. + * @todo - Use the class resolver at some point. * * @param \Drupal\Core\Menu\MenuLinkInterface $menu_link * The menu link. * * @return \Drupal\Core\Menu\Form\MenuLinkFormInterface + * A form instance for editing the menu link. */ public function getPluginForm(MenuLinkInterface $menu_link); diff --git a/core/lib/Drupal/Core/Menu/MenuTreeStorage.php b/core/lib/Drupal/Core/Menu/MenuTreeStorage.php index eaf2c18..3931a3a 100644 --- a/core/lib/Drupal/Core/Menu/MenuTreeStorage.php +++ b/core/lib/Drupal/Core/Menu/MenuTreeStorage.php @@ -109,7 +109,7 @@ class MenuTreeStorage implements MenuTreeStorageInterface { * @param array $options * (optional) Any additional database connection options to use in queries. */ - public function __construct(Connection $connection, UrlGeneratorInterface $url_generator, $table = 'menu_tree', array $options = array()) { + public function __construct(Connection $connection, UrlGeneratorInterface $url_generator, $table, array $options = array()) { $this->connection = $connection; $this->urlGenerator = $url_generator; $this->table = $table; @@ -233,7 +233,7 @@ protected function safeExecuteSelect(SelectInterface $query) { public function save(array $link) { $original = $this->loadFull($link['id']); // @todo - should we just return here if the links values match the original - // values completely?. + // values completely?. $affected_menus = array(); @@ -337,9 +337,9 @@ protected function preSave(array &$link, array $original) { // and fill parents based on the parent link. else { // @todo - we want to also check $original['has_children'] here, but that - // will be 0 even if there are children if those are hidden. has_children - // is really just the rendering hint. So, we either need to define - // another column (has_any_children), or always do the extra query here. + // will be 0 even if there are children if those are hidden. + // has_children is really just the rendering hint. So, we either need + // to define another column (has_any_children), or do the extra query. if ($original) { $limit = $this->maxDepth() - $this->doFindChildrenRelativeDepth($original) - 1; } @@ -352,7 +352,8 @@ protected function preSave(array &$link, array $original) { $this->setParents($fields, $parent); } - // Need to check both parent and menu_name, since parent can be NULL in any menu. + // Need to check both parent and menu_name, since parent can be empty in any + // menu. if ($original && ($link['parent'] != $original['parent'] || $link['menu_name'] != $original['menu_name'])) { $this->moveChildren($fields, $original); } @@ -495,11 +496,13 @@ protected function moveChildren($fields, $original) { /** * Loads the parent definition if it exists. * - * @param $link - * @param $original - * @internal param $ + * @param array $link + * The link definition to check. + * @param array|FALSE $original + * The original link, or FALSE. * - * @return array + * @return array|FALSE + * Returns a definition array, or FALSE if no parent was found. */ protected function findParent($link, $original) { $parent = FALSE; @@ -531,9 +534,10 @@ protected function findParent($link, $original) { } /** - * Sets the has_children flag for the link's parent if it has visible children. + * Set the has_children flag for the link's parent if it has visible children. * * @param array $link + * The link to get a parent ID from. */ protected function updateParentalStatus(array $link) { // If parent is empty, there is nothing to update. @@ -664,7 +668,7 @@ protected function loadFullMultiple(array $ids) { */ public function getRootPathIds($id) { $subquery = $this->connection->select($this->table, $this->options); - // @todo: consider making this dynamic based on static::MAX_DEPTH + // @todo - consider making this dynamic based on static::MAX_DEPTH // or from the schema if that is generated using static::MAX_DEPTH. $subquery->fields($this->table, array('p1', 'p2', 'p3', 'p4', 'p5', 'p6', 'p7', 'p8', 'p9')); $subquery->condition('id', $id); @@ -675,7 +679,7 @@ public function getRootPathIds($id) { $query->fields($this->table, array('id')); $query->orderBy('depth', 'DESC'); $query->condition('mlid', $ids, 'IN'); - // @todo: cache this result in memory if we find it's being used more + // @todo - cache this result in memory if we find it's being used more // than once per page load. return $this->safeExecuteSelect($query)->fetchAllKeyed(0, 0); } @@ -686,8 +690,8 @@ public function getRootPathIds($id) { * {@inheritdoc} */ public function getExpanded($menu_name, array $parents) { - // @todo go back to tracking in state or some other way - // which menus have expanded links? + // @todo - go back to tracking in state or some other way + // which menus have expanded links? do { $query = $this->connection->select($this->table, $this->options); $query->fields($this->table, array('id')); @@ -709,7 +713,7 @@ public function getExpanded($menu_name, array $parents) { protected function saveRecursive($id, &$children, &$links) { if (!empty($links[$id]['parent']) && empty($links[$links[$id]['parent']])) { - // Invalid parent ID, so remove it + // Invalid parent ID, so remove it. $links[$id]['parent'] = ''; } $this->save($links[$id]); @@ -906,6 +910,7 @@ protected function doBuildTreeData(array $links, array $parents = array(), $dept * The minimum depth to include in the returned menu tree. * * @return array + * The fully build tree. */ protected function treeDataRecursive(&$links, $parents, $depth) { $tree = array(); @@ -961,10 +966,10 @@ protected function ensureTableExists() { return TRUE; } } + catch (SchemaObjectExistsException $e) { // If another process has already created the config table, attempting to // recreate it will throw an exception. In this case just catch the // exception and do nothing. - catch (SchemaObjectExistsException $e) { return TRUE; } catch (\Exception $e) { @@ -1217,7 +1222,7 @@ protected static function schemaDefinition() { ), 'indexes' => array( 'menu_parents' => array('menu_name', 'p1', 'p2', 'p3', 'p4', 'p5', 'p6', 'p7', 'p8', 'p9'), - // @todo test this index for effectiveness. + // @todo - test this index for effectiveness. 'menu_parent_expand_child' => array('menu_name', 'expanded', 'has_children', array('parent', 16)), 'route_values' => array(array('route_name', 32), array('route_param_key', 16)), ), diff --git a/core/lib/Drupal/Core/Menu/MenuTreeStorageInterface.php b/core/lib/Drupal/Core/Menu/MenuTreeStorageInterface.php index 3f1d80b..d90a767 100644 --- a/core/lib/Drupal/Core/Menu/MenuTreeStorageInterface.php +++ b/core/lib/Drupal/Core/Menu/MenuTreeStorageInterface.php @@ -13,6 +13,7 @@ * The maximum depth of tree the storage implementation supports. * * @return int + * The maximum depth. */ public function maxDepth(); @@ -31,6 +32,7 @@ public function rebuild(array $definitions); * * @param string $id * The menu link plugin ID. + * * @return array|FALSE * Menu Link definition */ @@ -40,7 +42,7 @@ public function load($id); * Loads multiple plugin definitions from the storage. * * @param array $ids - * An array of plugin IDs. + * An array of plugin IDs. * * @return array * An array of menu Link definitions. @@ -70,7 +72,7 @@ public function loadByProperties(array $properties); * Defaults to FALSE. * * @return array - * An array of menu link definitions keyed by ID. + * An array of menu link definitions keyed by ID. */ public function loadByRoute($route_name, array $route_parameters = array(), $include_hidden = FALSE); @@ -176,6 +178,7 @@ public function getAllChildIds($id); * The maximum depth of child menu links relative to the passed in. * * @return array + * A fully built menu subtree. */ public function loadSubtree($id, $max_relative_depth = NULL); @@ -194,12 +197,15 @@ public function loadSubtree($id, $max_relative_depth = NULL); public function getRootPathIds($id); /** + * Find expanded links in a menu given a set of possible parents. + * * @param string $menu_name * The menu name. * @param array $parents + * One or more parent IDs to match. * * @return array - * The menu link ID that are flagged as expanded in this menu. + * The menu link IDs that are flagged as expanded in this menu. */ public function getExpanded($menu_name, array $parents); diff --git a/core/lib/Drupal/Core/Menu/StaticMenuLinkOverrides.php b/core/lib/Drupal/Core/Menu/StaticMenuLinkOverrides.php index 50d2d2c..0c7a94b 100644 --- a/core/lib/Drupal/Core/Menu/StaticMenuLinkOverrides.php +++ b/core/lib/Drupal/Core/Menu/StaticMenuLinkOverrides.php @@ -35,6 +35,12 @@ class StaticMenuLinkOverrides implements StaticMenuLinkOverridesInterface { */ protected $configFactory; + /** + * Constructs a StaticMenuLinkOverrides object. + * + * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory + * A configuration factory instance. + */ public function __construct(ConfigFactoryInterface $config_factory) { $this->configFactory = $config_factory; } @@ -118,7 +124,14 @@ public function loadMultipleOverrides(array $ids) { */ public function saveOverride($id, array $definition) { // Remove unexpected keys. - $definition = array_intersect_key($definition, array('menu_name' => 1, 'parent' => 1, 'weight' => 1, 'expanded' => 1, 'hidden' => 1)); + $expected = array( + 'menu_name' => 1, + 'parent' => 1, + 'weight' => 1, + 'expanded' => 1, + 'hidden' => 1, + ); + $definition = array_intersect_key($definition, $expected); if ($definition) { $id = static::encodeId($id); $all_overrides = $this->getConfig()->get('definitions'); @@ -137,6 +150,7 @@ public function saveOverride($id, array $definition) { * * @param string $id * The menu plugin ID. + * * @return string * The menu plugin ID with double underscore instead of dots. */ diff --git a/core/modules/menu_link_content/menu_link_content.install b/core/modules/menu_link_content/menu_link_content.install index 03fe225..606ca6a 100644 --- a/core/modules/menu_link_content/menu_link_content.install +++ b/core/modules/menu_link_content/menu_link_content.install @@ -17,4 +17,3 @@ function menu_link_content_uninstall() { $menu_tree->deleteLink("menu_link_content:$uuid", FALSE); } } - diff --git a/core/modules/menu_link_content/menu_link_content.module b/core/modules/menu_link_content/menu_link_content.module index 5e6ff93..6648280 100644 --- a/core/modules/menu_link_content/menu_link_content.module +++ b/core/modules/menu_link_content/menu_link_content.module @@ -1,9 +1,14 @@ getStorage('menu_link_content'); diff --git a/core/modules/menu_link_content/src/Controller/MenuController.php b/core/modules/menu_link_content/src/Controller/MenuController.php index 5f93db8..7ffa9f8 100644 --- a/core/modules/menu_link_content/src/Controller/MenuController.php +++ b/core/modules/menu_link_content/src/Controller/MenuController.php @@ -32,4 +32,3 @@ public function addLink(MenuInterface $menu) { } } - diff --git a/core/modules/menu_link_content/src/Entity/MenuLinkContent.php b/core/modules/menu_link_content/src/Entity/MenuLinkContent.php index 347d577..c98ef42 100644 --- a/core/modules/menu_link_content/src/Entity/MenuLinkContent.php +++ b/core/modules/menu_link_content/src/Entity/MenuLinkContent.php @@ -181,9 +181,10 @@ public function getWeight() { } /** - * Builds up the menu plugin definition for this entity. + * Builds up the menu link plugin definition for this entity. * * @return array + * The plugin definition corresponding to this entity. * * @see \Drupal\Core\Menu\MenuLinkTree::$defaults */ @@ -308,8 +309,8 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { $fields['menu_name'] = FieldDefinition::create('string') ->setLabel(t('Menu name')) - ->setDescription(t('The menu name. All links with the same menu name (such as "tools") are part of the same menu.')); - // ->setSetting('default_value', 'tools') + ->setDescription(t('The menu name. All links with the same menu name (such as "tools") are part of the same menu.')) + ->setSetting('default_value', 'tools'); // @todo use a link field in the end? see https://drupal.org/node/2235457 $fields['route_name'] = FieldDefinition::create('string') @@ -379,4 +380,3 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { } } - diff --git a/core/modules/menu_link_content/src/Entity/MenuLinkContentInterface.php b/core/modules/menu_link_content/src/Entity/MenuLinkContentInterface.php index acf1a4c..35a24a7 100644 --- a/core/modules/menu_link_content/src/Entity/MenuLinkContentInterface.php +++ b/core/modules/menu_link_content/src/Entity/MenuLinkContentInterface.php @@ -22,7 +22,8 @@ public function setInsidePlugin(); /** * Gets the title of the menu link. * - * @return mixed + * @return string + * The title of the link. */ public function getTitle(); @@ -38,6 +39,7 @@ public function getRouteName(); * Gets the route parameters of the custom menu link. * * @return array + * The route parameters, or an empty array. */ public function getRouteParameters(); @@ -64,6 +66,7 @@ public function getUrl(); * Gets the url object pointing to the URL of the custom menu link. * * @return \Drupal\Core\Url + * A Url object instance. */ public function getUrlObject(); @@ -76,9 +79,10 @@ public function getUrlObject(); public function getMenuName(); /** - * Gets the query options of the custom menu link. + * Gets the options for the custom menu link. * * @return array + * The options that may be passed to the URL generator. */ public function getOptions(); @@ -96,6 +100,7 @@ public function setOptions(array $options); * Gets the description of the custom menu link for the UI. * * @return string + * The descption for use on admin pages or as a title attribute. */ public function getDescription(); @@ -103,6 +108,7 @@ public function getDescription(); * Gets the menu plugin ID associated with this entity. * * @return string + * The plugin ID. */ public function getPluginId(); @@ -118,13 +124,15 @@ public function isHidden(); * Returns whether the menu link is marked as always expanded. * * @return bool + * TRUE for expanded, FALSE otherwise. */ public function isExpanded(); /** - * Gets the menu plugin ID of the parent menu link. + * Gets the plugin ID of the parent menu link. * * @return string + * A plugin ID, or empty string if this link is at the top level. */ public function getParentId(); @@ -132,6 +140,7 @@ public function getParentId(); * Returns the weight of the custom menu link. * * @return int + * A weight for use when ordering links. */ public function getWeight(); diff --git a/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php b/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php index 6ad7c8a..272ac64 100644 --- a/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php +++ b/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php @@ -147,6 +147,7 @@ public function submitEditForm(array &$form, array &$form_state) { * Break up a user-entered URL or path into all the relevant parts. * * @param string $url + * The user-entered URL or path. * * @return array * The extracted parts. @@ -176,7 +177,7 @@ protected function extractUrl($url) { } catch (ParamNotConvertedException $e) { // A path like node/99 matched a route, but the route parameter was - // invalid (e.g. node with ID 99 does not exist) + // invalid (e.g. node with ID 99 does not exist). } } return $extracted; @@ -256,7 +257,7 @@ public function form(array $form, array &$form_state) { if ($url->isExternal()) { $default_value = $url->toString(); } - elseif($url->getRouteName() == '') { + elseif ($url->getRouteName() == '') { // The default route for new entities is , but we just want an // empty form field. $default_value = $this->getEntity()->isNew() ? '' : ''; @@ -283,7 +284,7 @@ public function form(array $form, array &$form_state) { ); $options = $this->menuTree->getParentSelectOptions($this->entity->getPluginId()); - $menu_parent = $this->entity->getMenuName() . ':' . $this->entity->getParentId(); + $menu_parent = $this->entity->getMenuName() . ':' . $this->entity->getParentId(); if (!isset($options[$menu_parent])) { // Put it at the top level in the current menu. @@ -312,6 +313,9 @@ protected function actions(array $form, array &$form_state) { return $element; } + /** + * {@inheritdoc} + */ public function validate(array $form, array &$form_state) { $this->doValidate($form, $form_state); @@ -387,7 +391,7 @@ protected function doValidate(array $form, array &$form_state) { if ($extracted['path'] != $normal_path) { drupal_set_message($this->t('The menu system stores system paths only, but will use the URL alias for display. %link_path has been stored as %normal_path', array( '%link_path' => $extracted['path'], - '%normal_path' => $normal_path + '%normal_path' => $normal_path, ))); } } diff --git a/core/modules/menu_link_content/src/MenuLinkContentAccessController.php b/core/modules/menu_link_content/src/MenuLinkContentAccessController.php index fd59e28..d895478 100644 --- a/core/modules/menu_link_content/src/MenuLinkContentAccessController.php +++ b/core/modules/menu_link_content/src/MenuLinkContentAccessController.php @@ -30,16 +30,13 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A case 'view': // There is no direct view. return FALSE; - break; case 'update': // If there is a URL, this is an external link so always accessible. return $account->hasPermission('administer menu') && ($entity->getUrl() || $this->accessManager()->checkNamedRoute($entity->getRouteName(), $entity->getRouteParameters(), $account)); - break; case 'delete': return !$entity->isNew() && $account->hasPermission('administer menu'); - break; } } @@ -55,4 +52,4 @@ protected function accessManager() { } return $this->accessManager; } -} \ No newline at end of file +} diff --git a/core/modules/menu_link_content/src/Plugin/Menu/MenuLinkContent.php b/core/modules/menu_link_content/src/Plugin/Menu/MenuLinkContent.php index 8ef24fb..15c5370 100644 --- a/core/modules/menu_link_content/src/Plugin/Menu/MenuLinkContent.php +++ b/core/modules/menu_link_content/src/Plugin/Menu/MenuLinkContent.php @@ -104,6 +104,7 @@ public static function create(ContainerInterface $container, array $configuratio * Loads the entity associated with this menu link. * * @return \Drupal\menu_link_content\Entity\MenuLinkContentInterface + * The menu link content entity. * * @throws \Drupal\Component\Plugin\Exception\PluginException * If the entity ID and uuid are both invalid or missing. @@ -184,11 +185,11 @@ public function getEditRoute() { */ public function getTranslateRoute() { $entity_type = $this->getEntity()->getEntityType()->id(); - return array ( + return array( 'route_name' => 'content_translation.translation_overview_' . $entity_type, - 'route_parameters' => array ( - $entity_type => $this->getEntity()->id(), - ) + 'route_parameters' => array( + $entity_type => $this->getEntity()->id(), + ), ); } diff --git a/core/modules/menu_link_content/src/Tests/MenuLinkContentUITest.php b/core/modules/menu_link_content/src/Tests/MenuLinkContentUITest.php index c3952f2..7bbcf80 100644 --- a/core/modules/menu_link_content/src/Tests/MenuLinkContentUITest.php +++ b/core/modules/menu_link_content/src/Tests/MenuLinkContentUITest.php @@ -35,7 +35,7 @@ public static function getInfo() { /** * {@inheritdoc} */ - function setUp() { + protected function setUp() { $this->entityTypeId = 'menu_link_content'; $this->bundle = 'menu_link_content'; $this->fieldName = 'title'; @@ -61,4 +61,3 @@ protected function createEntity($values, $langcode, $bundle_name = NULL) { } } - diff --git a/core/modules/menu_ui/menu_ui.admin.inc b/core/modules/menu_ui/menu_ui.admin.inc index 2021be0..00d3e58 100644 --- a/core/modules/menu_ui/menu_ui.admin.inc +++ b/core/modules/menu_ui/menu_ui.admin.inc @@ -11,10 +11,13 @@ /** * Returns HTML for the menu overview form into a table. * - * @param $variables + * @param array $variables * An associative array containing: * - form: A render element representing the form. * + * @return string + * The themed HTML. + * * @ingroup themeable */ function theme_menu_overview_form($variables) { @@ -37,7 +40,8 @@ function theme_menu_overview_form($variables) { $element['id']['#attributes']['class'] = array('menu-id'); $element['weight']['#attributes']['class'] = array('menu-weight'); - // Change the parent field to a hidden. This allows any value but hides the field. + // Change the parent field to a hidden. This allows any value but hides + // the field. $element['parent']['#type'] = 'hidden'; $indent = array( diff --git a/core/modules/menu_ui/src/Form/MenuLinkResetForm.php b/core/modules/menu_ui/src/Form/MenuLinkResetForm.php index 7d1ef62..2fb02d7 100644 --- a/core/modules/menu_ui/src/Form/MenuLinkResetForm.php +++ b/core/modules/menu_ui/src/Form/MenuLinkResetForm.php @@ -52,6 +52,9 @@ public static function create(ContainerInterface $container) { ); } + /** + * {@inheritdoc} + */ public function getFormId() { return 'menu_link_reset_confirm'; } diff --git a/core/modules/menu_ui/src/MenuForm.php b/core/modules/menu_ui/src/MenuForm.php index d182789..c1eba69 100644 --- a/core/modules/menu_ui/src/MenuForm.php +++ b/core/modules/menu_ui/src/MenuForm.php @@ -112,7 +112,7 @@ public function form(array $form, array &$form_state) { // Add menu links administration form for existing menus. if (!$menu->isNew() || $menu->isLocked()) { // Form API supports constructing and validating self-contained sections - // within forms, but does not allow to handle the form section's submission + // within forms, but does not allow handling the form section's submission // equally separated yet. Therefore, we use a $form_state key to point to // the parents of the form section. // @see self::submitOverviewForm() @@ -167,6 +167,9 @@ public function save(array $form, array &$form_state) { $form_state['redirect_route'] = $this->entity->urlInfo('edit-form'); } + /** + * Recursively count the number of menu links in a tree. + */ protected function countElements($tree, $count = 0) { foreach ($tree as $element) { $count++; @@ -296,9 +299,9 @@ protected function buildOverviewTreeForm($tree, $delta) { $operations['delete']['title'] = $this->t('Delete'); } if ($item->isTranslatable()) { - $operations['translate'] = array ( + $operations['translate'] = array( 'title' => $this->t('Translate'), - ) + (array)$item->getTranslateRoute(); + ) + (array) $item->getTranslateRoute(); } $form[$id]['operations'] = array( '#type' => 'operations', @@ -317,7 +320,7 @@ protected function buildOverviewTreeForm($tree, $delta) { * Submit handler for the menu overview form. * * This function takes great care in saving parent items first, then items - * underneath them. Saving items in the incorrect order can break the menu tree. + * underneath them. Saving items in the incorrect order can break the tree. */ protected function submitOverviewForm(array $complete_form, array &$form_state) { // Form API supports constructing and validating self-contained sections diff --git a/core/modules/menu_ui/src/Plugin/Menu/LocalAction/MenuLinkAdd.php b/core/modules/menu_ui/src/Plugin/Menu/LocalAction/MenuLinkAdd.php index ad27fce..88e1898 100644 --- a/core/modules/menu_ui/src/Plugin/Menu/LocalAction/MenuLinkAdd.php +++ b/core/modules/menu_ui/src/Plugin/Menu/LocalAction/MenuLinkAdd.php @@ -30,4 +30,3 @@ public function getOptions(Request $request) { } } - diff --git a/core/modules/menu_ui/src/Tests/MenuCacheTagsTest.php b/core/modules/menu_ui/src/Tests/MenuCacheTagsTest.php index c7402bc..138c132 100644 --- a/core/modules/menu_ui/src/Tests/MenuCacheTagsTest.php +++ b/core/modules/menu_ui/src/Tests/MenuCacheTagsTest.php @@ -67,7 +67,6 @@ public function testMenuBlock() { ); $this->verifyPageCache($path, 'HIT', $expected_tags); - // Verify that after modifying the menu, there is a cache miss. $this->pass('Test modification of menu.', 'Debug'); $menu->label = 'Awesome llama'; @@ -77,7 +76,6 @@ public function testMenuBlock() { // Verify a cache hit. $this->verifyPageCache($path, 'HIT'); - // Verify that after modifying the menu link weight, there is a cache miss. $menu_tree->updateLink('test_page_test.test_page', array('weight' => -10)); $this->pass('Test modification of menu link.', 'Debug'); @@ -86,7 +84,6 @@ public function testMenuBlock() { // Verify a cache hit. $this->verifyPageCache($path, 'HIT'); - // Verify that after adding a menu link, there is a cache miss. $this->pass('Test addition of menu link.', 'Debug'); @@ -104,7 +101,6 @@ public function testMenuBlock() { // Verify a cache hit. $this->verifyPageCache($path, 'HIT'); - // Verify that after resetting the first menu link, there is a cache miss. $this->pass('Test reset of menu link.', 'Debug'); $this->assertTrue($menu_link->isResetable(), 'First link can be reset');