diff --git a/core/modules/menu/lib/Drupal/menu/MenuFormController.php b/core/modules/menu/lib/Drupal/menu/MenuFormController.php index 9a7d93b..ea2db6b 100644 --- a/core/modules/menu/lib/Drupal/menu/MenuFormController.php +++ b/core/modules/menu/lib/Drupal/menu/MenuFormController.php @@ -127,9 +127,9 @@ class MenuFormController extends EntityFormController { // 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 - // equally separated yet. Therefore, we use a $form_state key to point to - // the parents of the form section. + // within forms, but does not allow to handle 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() $form_state['menu_overview_form_parents'] = array('links'); $form['links'] = array(); @@ -169,7 +169,7 @@ class MenuFormController extends EntityFormController { // Add the language configuration submit handler. This is needed because the // submit button has custom submit handlers. if ($this->moduleHandler->moduleExists('language')) { - array_unshift($actions['submit']['#submit'],'language_configuration_element_submit'); + array_unshift($actions['submit']['#submit'], 'language_configuration_element_submit'); array_unshift($actions['submit']['#submit'], array($this, 'languageConfigurationSubmit')); } // We cannot leverage the regular submit handler definition because we have @@ -266,7 +266,7 @@ class MenuFormController extends EntityFormController { $menu_admin = FALSE; $form = array_merge($form, $this->buildOverviewTreeForm($tree, $delta)); - $form['#empty_text'] = t('There are no menu links yet. Add link.', array('@link' => url('admin/structure/menu/manage/' . $this->entity->id() .'/add'))); + $form['#empty_text'] = t('There are no menu links yet. Add link.', array('@link' => url('admin/structure/menu/manage/' . $this->entity->id() . '/add'))); return $form; } @@ -357,7 +357,8 @@ class MenuFormController extends EntityFormController { * 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 menu + * 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/lib/Drupal/menu/MenuListController.php b/core/modules/menu/lib/Drupal/menu/MenuListController.php index 18a3732..0fcfa0b 100644 --- a/core/modules/menu/lib/Drupal/menu/MenuListController.php +++ b/core/modules/menu/lib/Drupal/menu/MenuListController.php @@ -1,6 +1,7 @@ randomName(16)); @@ -61,7 +61,7 @@ function testMenuLanguage() { $edit = array( 'id' => $menu_name, 'description' => '', - 'label' => $label, + 'label' => $label, 'langcode' => 'aa', 'default_language[langcode]' => 'bb', 'default_language[language_show]' => TRUE, @@ -161,7 +161,7 @@ function testMenuLanguage() { /** * Tests menu configuration is still English after English has been deleted. */ - function testMenuLanguageRemovedEnglish() { + public function testMenuLanguageRemovedEnglish() { // Create a test menu to test language settings. // Machine name has to be lowercase. $menu_name = Unicode::strtolower($this->randomName(16)); diff --git a/core/modules/menu/lib/Drupal/menu/Tests/MenuNodeTest.php b/core/modules/menu/lib/Drupal/menu/Tests/MenuNodeTest.php index d8fdea8..ac5ebbb 100644 --- a/core/modules/menu/lib/Drupal/menu/Tests/MenuNodeTest.php +++ b/core/modules/menu/lib/Drupal/menu/Tests/MenuNodeTest.php @@ -29,7 +29,7 @@ class MenuNodeTest extends WebTestBase { ); } - function setUp() { + public function setUp() { parent::setUp(); $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page')); @@ -47,7 +47,7 @@ function setUp() { /** * Test creating, editing, deleting menu links via node form widget. */ - function testMenuNodeFormWidget() { + public function testMenuNodeFormWidget() { // Disable the default main menu, so that no menus are enabled. $edit = array( 'menu_options[main]' => FALSE, @@ -143,16 +143,17 @@ function testMenuNodeFormWidget() { $child_node = $this->drupalCreateNode(array('type' => 'article')); // Assign a menu link to the second node, being a child of the first one. $child_item = entity_create('menu_link', array( - 'link_path' => 'node/'. $child_node->id(), + 'link_path' => 'node/' . $child_node->id(), 'link_title' => $this->randomName(16), 'plid' => $item['mlid'], )); $child_item->save(); // Edit the first node. - $this->drupalGet('node/'. $node->id() .'/edit'); - // Assert that it is not possible to set the parent of the first node to itself or the second node. - $this->assertNoOption('edit-menu-parent', 'tools:'. $item['mlid']); - $this->assertNoOption('edit-menu-parent', 'tools:'. $child_item['mlid']); + $this->drupalGet('node/' . $node->id() . '/edit'); + // Assert that it is not possible to set the parent of the first node to + // itself or the second node. + $this->assertNoOption('edit-menu-parent', 'tools:' . $item['mlid']); + $this->assertNoOption('edit-menu-parent', 'tools:' . $child_item['mlid']); // Assert that unallowed Administration menu is not available in options. $this->assertNoOption('edit-menu-parent', 'admin:0'); } diff --git a/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php b/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php index d926528..6766a4c 100644 --- a/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php +++ b/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php @@ -51,11 +51,11 @@ class MenuTest extends MenuWebTestBase { return array( 'name' => 'Menu link creation/deletion', 'description' => 'Add a custom menu, add menu links to the custom menu and Tools menu, check their data, and delete them using the menu module UI.', - 'group' => 'Menu' + 'group' => 'Menu', ); } - function setUp() { + public function setUp() { parent::setUp(); $this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article')); @@ -68,7 +68,7 @@ function setUp() { /** * Tests menu functionality using the admin and user interfaces. */ - function testMenu() { + public function testMenu() { // Login the user. $this->drupalLogin($this->admin_user); $this->items = array(); @@ -125,7 +125,7 @@ function testMenu() { /** * Adds a custom menu using CRUD functions. */ - function addCustomMenuCRUD() { + public function addCustomMenuCRUD() { // Add a new custom menu. $menu_name = substr(hash('sha256', $this->randomName(16)), 0, MENU_MAX_MENU_NAME_LENGTH_UI); $label = $this->randomName(16); @@ -155,7 +155,7 @@ function addCustomMenuCRUD() { * @return \Drupal\system\Entity\Menu * The custom menu that has been created. */ - function addCustomMenu() { + public function addCustomMenu() { // Try adding a menu using a menu_name that is too long. $this->drupalGet('admin/structure/menu/add'); $menu_name = substr(hash('sha256', $this->randomName(16)), 0, MENU_MAX_MENU_NAME_LENGTH_UI + 1); @@ -163,7 +163,7 @@ function addCustomMenu() { $edit = array( 'id' => $menu_name, 'description' => '', - 'label' => $label, + 'label' => $label, ); $this->drupalPostForm('admin/structure/menu/add', $edit, t('Save')); @@ -206,7 +206,7 @@ function addCustomMenu() { * This deletes the custom menu that is stored in $this->menu and performs * tests on the menu delete user interface. */ - function deleteCustomMenu() { + public function deleteCustomMenu() { $menu_name = $this->menu->id(); $label = $this->menu->label(); @@ -231,7 +231,7 @@ function deleteCustomMenu() { /** * Tests menu functionality. */ - function doMenuTests() { + public function doMenuTests() { $menu_name = $this->menu->id(); // Add nodes to use as links for menu links. $node1 = $this->drupalCreateNode(array('type' => 'article')); @@ -401,7 +401,7 @@ function doMenuTests() { /** * Adds and removes a menu link with a query string and fragment. */ - function testMenuQueryAndFragment() { + public function testMenuQueryAndFragment() { $this->drupalLogin($this->admin_user); // Make a path with query and fragment on. @@ -421,7 +421,7 @@ function testMenuQueryAndFragment() { /** * Tests renaming the built-in menu. */ - function testSystemMenuRename() { + public function testSystemMenuRename() { $this->drupalLogin($this->admin_user); $edit = array( 'label' => $this->randomName(16), @@ -437,7 +437,7 @@ function testSystemMenuRename() { /** * Tests that menu items pointing to unpublished nodes are editable. */ - function testUnpublishedNodeMenuItem() { + public function testUnpublishedNodeMenuItem() { $this->drupalLogin($this->drupalCreateUser(array('access administration pages', 'administer blocks', 'administer menu', 'create article content', 'bypass node access'))); // Create an unpublished node. $node = $this->drupalCreateNode(array( @@ -467,12 +467,12 @@ function testUnpublishedNodeMenuItem() { $id = 'block:block=' . $block->id() . ':|menu:menu=tools:'; // @see \Drupal\contextual\Tests\ContextualDynamicContextTest:assertContextualLinkPlaceHolder() - $this->assertRaw('
', format_string('Contextual link placeholder with id @id exists.', array('@id' => $id))); + $this->assertRaw('
', format_string('Contextual link placeholder with id @id exists.', array('@id' => $id))); // Get server-rendered contextual links. // @see \Drupal\contextual\Tests\ContextualDynamicContextTest:renderContextualLinks() $post = array('ids[0]' => $id); - $response = $this->drupalPost('contextual/render', 'application/json', $post, array('query' => array('destination' => 'test-page'))); + $response = $this->drupalPost('contextual/render', 'application/json', $post, array('query' => array('destination' => 'test-page'))); $this->assertResponse(200); $json = drupal_json_decode($response); $this->assertIdentical($json[$id], ''); @@ -571,7 +571,7 @@ function testUnpublishedNodeMenuItem() { /** * Adds a menu link using the menu module UI. * - * @param integer $plid + * @param int $plid * Optional parent menu link id. * @param string $link * Link path. Defaults to the front page. @@ -582,14 +582,14 @@ function testUnpublishedNodeMenuItem() { * test whether it works when we do the authenticated_user tests. Defaults * to FALSE. * @param string $weight - * Menu weight. Defaults to 0. + * Menu weight. Defaults to 0. * @param string $actual_link * Actual link path in case $link is an alias. * * @return \Drupal\menu_link\Entity\MenuLink * A menu link entity. */ - function addMenuLink($plid = 0, $link = '', $menu_name = 'tools', $expanded = TRUE, $weight = '0', $actual_link = FALSE) { + public function addMenuLink($plid = 0, $link = '', $menu_name = 'tools', $expanded = TRUE, $weight = '0', $actual_link = FALSE) { // View add menu link page. $this->drupalGet("admin/structure/menu/manage/$menu_name/add"); $this->assertResponse(200); @@ -601,7 +601,7 @@ function addMenuLink($plid = 0, $link = '', $menu_name = 'tools', $expand 'description' => '', 'enabled' => TRUE, 'expanded' => $expanded, - 'parent' => $menu_name . ':' . $plid, + 'parent' => $menu_name . ':' . $plid, 'weight' => $weight, ); @@ -624,7 +624,7 @@ function addMenuLink($plid = 0, $link = '', $menu_name = 'tools', $expand /** * Attempts to add menu link with invalid path or no access permission. */ - function addInvalidMenuLink() { + public function addInvalidMenuLink() { foreach (array('-&-', 'admin/people/permissions', '#') as $link_path) { $edit = array( 'link_path' => $link_path, @@ -647,7 +647,7 @@ function addInvalidMenuLink() { * @param object $parent_node * Parent menu link content node. */ - function verifyMenuLink($item, $item_node, $parent = NULL, $parent_node = NULL) { + public function verifyMenuLink($item, $item_node, $parent = NULL, $parent_node = NULL) { // View home page. $this->drupalGet(''); $this->assertResponse(200); @@ -684,7 +684,7 @@ function verifyMenuLink($item, $item_node, $parent = NULL, $parent_node = NULL) * @param string $menu_name * The menu the menu link will be moved to. */ - function moveMenuLink($item, $plid, $menu_name) { + public function moveMenuLink($item, $plid, $menu_name) { $mlid = $item['mlid']; $edit = array( @@ -700,7 +700,7 @@ function moveMenuLink($item, $plid, $menu_name) { * @param array $item * Menu link passed by reference. */ - function modifyMenuLink(&$item) { + public function modifyMenuLink(&$item) { $item['link_title'] = $this->randomName(16); $mlid = $item['mlid']; @@ -725,7 +725,7 @@ function modifyMenuLink(&$item) { * @param string $old_title * Original title for menu link. */ - function resetMenuLink($item, $old_title) { + public function resetMenuLink($item, $old_title) { $mlid = $item['mlid']; $title = $item['link_title']; @@ -746,7 +746,7 @@ function resetMenuLink($item, $old_title) { * @param array $item * Menu link. */ - function deleteMenuLink($item) { + public function deleteMenuLink($item) { $mlid = $item['mlid']; $title = $item['link_title']; @@ -766,7 +766,7 @@ function deleteMenuLink($item) { * @param $item * Menu link. */ - function toggleMenuLink($item) { + public function toggleMenuLink($item) { $this->disableMenuLink($item); // Verify menu link is absent. @@ -785,7 +785,7 @@ function toggleMenuLink($item) { * @param $item * Menu link. */ - function disableMenuLink($item) { + public function disableMenuLink($item) { $mlid = $item['mlid']; $edit['enabled'] = FALSE; $this->drupalPostForm("admin/structure/menu/item/$mlid/edit", $edit, t('Save')); @@ -801,7 +801,7 @@ function disableMenuLink($item) { * @param $item * Menu link. */ - function enableMenuLink($item) { + public function enableMenuLink($item) { $mlid = $item['mlid']; $edit['enabled'] = TRUE; $this->drupalPostForm("admin/structure/menu/item/$mlid/edit", $edit, t('Save')); @@ -811,6 +811,8 @@ function enableMenuLink($item) { } /** + * Tests if administrative users can access menu parents AJAX callback. + * * Tests if administrative users other than user 1 can access the menu parents * AJAX callback. */ @@ -857,7 +859,7 @@ function enableMenuLink($item) { /** * Verifies the logged in user has the desired access to various menu pages. * - * @param integer $response + * @param int $response * The expected HTTP response code. Defaults to 200. */ private function verifyAccess($response = 200) { @@ -877,7 +879,7 @@ function enableMenuLink($item) { // View tools menu customization page. $this->drupalGet('admin/structure/menu/manage/' . $this->menu->id()); - $this->assertResponse($response); + $this->assertResponse($response); if ($response == 200) { $this->assertText(t('Tools'), 'Tools menu page was displayed'); } diff --git a/core/modules/menu/lib/Drupal/menu/Tests/MenuWebTestBase.php b/core/modules/menu/lib/Drupal/menu/Tests/MenuWebTestBase.php index e1c21a0..4f42924 100644 --- a/core/modules/menu/lib/Drupal/menu/Tests/MenuWebTestBase.php +++ b/core/modules/menu/lib/Drupal/menu/Tests/MenuWebTestBase.php @@ -26,10 +26,10 @@ class MenuWebTestBase extends WebTestBase { * * @param int $mlid * Menu item id. - * @param array $item + * @param array $expected_item * Array containing properties to verify. */ - function assertMenuLink($mlid, array $expected_item) { + public function assertMenuLink($mlid, array $expected_item) { // Retrieve menu link. $item = entity_load('menu_link', $mlid); $options = $item->options; diff --git a/core/modules/menu/menu.admin.inc b/core/modules/menu/menu.admin.inc index 57bba6d..44d53bc 100644 --- a/core/modules/menu/menu.admin.inc +++ b/core/modules/menu/menu.admin.inc @@ -34,7 +34,8 @@ function theme_menu_overview_form($variables) { $element['mlid']['#attributes']['class'] = array('menu-mlid'); $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['plid']['#type'] = 'hidden'; $indent = array( diff --git a/core/modules/menu/menu.module b/core/modules/menu/menu.module index 3259353..8f8c841 100644 --- a/core/modules/menu/menu.module +++ b/core/modules/menu/menu.module @@ -43,6 +43,7 @@ function menu_help($path, $arg) { $output .= '
' . t('After you have created a menu, you must enable and position the associated block on the Blocks administration page.', array('@blocks' => url('admin/structure/block'))) . '
'; $output .= ''; return $output; + case 'admin/structure/menu/add': return '

' . t('You can enable the newly-created block for this menu on the Blocks administration page.', array('@blocks' => url('admin/structure/block'))) . '

'; } @@ -109,7 +110,7 @@ function menu_menu_link_defaults() { * Implements hook_entity_type_build(). */ function menu_entity_type_build(array &$entity_types) { - /** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */ + // @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] $entity_types['menu'] ->setFormClass('add', 'Drupal\menu\MenuFormController') ->setFormClass('edit', 'Drupal\menu\MenuFormController') @@ -158,7 +159,8 @@ function menu_theme() { * * @param $menu_name * The unique name of a custom menu to load. - * @return + * + * @return array * Array defining the custom menu, or NULL if the menu doesn't exist. */ function menu_load($menu_name) { @@ -166,7 +168,7 @@ function menu_load($menu_name) { } /** - * Implements hook_menu_insert() + * Implements hook_menu_insert(). */ function menu_menu_insert(Menu $menu) { menu_cache_clear_all(); @@ -233,6 +235,8 @@ function menu_menu_delete(Menu $menu) { } /** + * Returns a list of valid possible parents. + * * Returns a list of menu links that are valid possible parents for the given * menu link. * @@ -285,7 +289,8 @@ function menu_parent_options(array $menus, MenuLink $menu_link = NULL, $type = N * Helper function to get the items of the given menu. */ function _menu_get_options($menus, $available_menus, $item) { - // If the item has children, there is an added limit to the depth of valid parents. + // If the item has children, there is an added limit to the depth of valid + // parents. if (isset($item['parent_depth_limit'])) { $limit = $item['parent_depth_limit']; } @@ -327,7 +332,7 @@ function _menu_parents_recurse($tree, $menu_name, $indent, &$options, $exclude, } /** - * Implements hook_block_view_BASE_BLOCK_ID_alter() for 'system_menu_block'. + * Implements hook_block_view_BASE_BLOCK_ID_alter() for system_menu_block(). */ function menu_block_view_system_menu_block_alter(array &$build, BlockPluginInterface $block) { // Add contextual links for system menu blocks. @@ -428,7 +433,7 @@ function menu_node_prepare_form(NodeInterface $node, $form_display, $operation, $menu_link = FALSE; if ($node->id()) { $mlid = FALSE; - // Give priority to the default menu + // Give priority to the default menu. $type_menus = $node_type_config->get('available_menus'); if (in_array($menu_name, $type_menus)) { $query = \Drupal::entityQuery('menu_link') @@ -489,7 +494,7 @@ function _menu_parent_depth_limit($item) { * @see menu_node_submit() */ function menu_form_node_form_alter(&$form, $form_state) { - // Generate a list of possible parents (not including this link or descendants). + // Generate a list of possible parents not including this link or descendants. // @todo This must be handled in a #process handler. $node = $form_state['controller']->getEntity(); $link = $node->menu; @@ -551,7 +556,7 @@ function menu_form_node_form_alter(&$form, $form_state) { $default = $link['menu_name'] . ':' . $link['plid']; } else { - $default = \Drupal::config('menu.entity.node.'.$type)->get('parent'); + $default = \Drupal::config('menu.entity.node.' . $type)->get('parent'); } // If the current parent menu item is not present in options, use the first // available option as default value. @@ -572,7 +577,7 @@ function menu_form_node_form_alter(&$form, $form_state) { // Get number of items in menu so the weight selector is sized appropriately. $delta = entity_get_controller('menu_link')->countMenuLinks($link->menu_name); if ($delta < 50) { - // Old hardcoded value + // Old hardcoded value. $delta = 50; } $form['menu']['link']['weight'] = array( @@ -605,8 +610,8 @@ function menu_node_submit(EntityInterface $node, $form, $form_state) { * * Adds menu options to the node type form. * - * @see NodeTypeFormController::form(). - * @see menu_form_node_type_form_submit(). + * @see NodeTypeFormController::form() + * @see menu_form_node_type_form_submit() */ function menu_form_node_type_form_alter(&$form, $form_state) { $menu_options = menu_get_menus(); @@ -657,7 +662,7 @@ function menu_form_node_type_form_alter(&$form, $form_state) { /** * Submit handler for forms with menu options. * - * @see menu_form_node_type_form_alter(). + * @see menu_form_node_type_form_alter() */ function menu_form_node_type_form_submit(&$form, $form_state) { $type = $form_state['controller']->getEntity(); @@ -673,6 +678,7 @@ function menu_form_node_type_form_submit(&$form, $form_state) { * @param $all * If FALSE return only user-added menus, or if TRUE also include * the menus defined by the system. + * * @return * An array with the machine-readable names as the keys, and human-readable * titles as the values. @@ -691,7 +697,7 @@ function menu_get_menus($all = TRUE) { } /** - * Implements hook_preprocess_HOOK() for block templates. + * Implements hook_preprocess_HOOK() for block.html.twig. */ function menu_preprocess_block(&$variables) { if ($variables['configuration']['module'] == 'menu') {