Commit 4ae3ee3a authored by alexpott's avatar alexpott

Issue #2305707 by cilefen, pwolanin, dawehner, LinL: MenuLinkContent disabled...

Issue #2305707 by cilefen, pwolanin, dawehner, LinL: MenuLinkContent disabled field should be renamed to enabled and use positive logic.
parent 9c87059f
......@@ -22,6 +22,6 @@ menu_link.static.overrides:
expanded:
type: boolean
label: 'Expanded'
hidden:
enabled:
type: boolean
label: 'Hidden'
label: 'Enabled'
......@@ -124,7 +124,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
'#type' => 'checkbox',
'#title' => $this->t('Enable menu link'),
'#description' => $this->t('Menu links that are not enabled will not be listed in any menu.'),
'#default_value' => !$this->menuLink->isHidden(),
'#default_value' => $this->menuLink->isEnabled(),
);
$form['expanded'] = array(
......@@ -158,7 +158,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
*/
public function extractFormValues(array &$form, FormStateInterface $form_state) {
$new_definition = array();
$new_definition['hidden'] = $form_state->getValue('enabled') ? 0 : 1;
$new_definition['enabled'] = $form_state->getValue('enabled') ? 1 : 0;
$new_definition['weight'] = (int) $form_state->getValue('weight');
$new_definition['expanded'] = $form_state->getValue('expanded') ? 1 : 0;
list($menu_name, $parent) = explode(':', $form_state->getValue('menu_parent'), 2);
......
......@@ -61,8 +61,8 @@ public function getParent() {
/**
* {@inheritdoc}
*/
public function isHidden() {
return (bool) $this->pluginDefinition['hidden'];
public function isEnabled() {
return (bool) $this->pluginDefinition['enabled'];
}
/**
......
......@@ -23,7 +23,7 @@ class MenuLinkDefault extends MenuLinkBase implements ContainerFactoryPluginInte
'parent' => 1,
'weight' => 1,
'expanded' => 1,
'hidden' => 1,
'enabled' => 1,
);
/**
......
......@@ -64,12 +64,12 @@ public function getProvider();
public function getParent();
/**
* Returns whether the menu link is hidden.
* Returns whether the menu link is enabled (not hidden).
*
* @return bool
* TRUE for hidden, FALSE otherwise.
* TRUE for enabled, FALSE otherwise.
*/
public function isHidden();
public function isEnabled();
/**
* Returns whether the child menu links should always been shown.
......
......@@ -58,7 +58,7 @@ class MenuLinkManager implements MenuLinkManagerInterface {
// The default link options.
'options' => array(),
'expanded' => 0,
'hidden' => 0,
'enabled' => 1,
// The name of the module providing this link.
'provider' => '',
'metadata' => array(),
......
......@@ -205,7 +205,7 @@ public function build(array $tree) {
/** @var \Drupal\Core\Menu\MenuLinkInterface $link */
$link = $data->link;
// Generally we only deal with visible links, but just in case.
if ($link->isHidden()) {
if (!$link->isEnabled()) {
continue;
}
// Set a class for the <li>-tag. Only set 'expanded' class if the link
......
......@@ -143,7 +143,7 @@ protected function parentSelectOptionsTreeWalk(array $tree, $menu_name, $indent,
$link = $element->link;
if ($link->getPluginId() != $exclude) {
$title = $indent . ' ' . Unicode::truncate($link->getTitle(), 30, TRUE, FALSE);
if ($link->isHidden()) {
if (!$link->isEnabled()) {
$title .= ' (' . $this->t('disabled') . ')';
}
$options[$menu_name . ':' . $link->getPluginId()] = $title;
......
......@@ -184,12 +184,12 @@ public function addCondition($definition_field, $value, $operator = NULL) {
}
/**
* Excludes hidden links.
* Excludes links that are not enabled.
*
* @return $this
*/
public function excludeHiddenLinks() {
$this->addCondition('hidden', 0);
public function onlyEnabledLinks() {
$this->addCondition('enabled', 1);
return $this;
}
......
......@@ -94,7 +94,7 @@ class MenuTreeStorage implements MenuTreeStorageInterface {
'weight',
'options',
'expanded',
'hidden',
'enabled',
'provider',
'metadata',
'class',
......@@ -384,7 +384,7 @@ 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.
// will be 0 even if there are children if those are not enabled.
// has_children is really just the rendering hint. So, we either need
// to define another column (has_any_children), or do the extra query.
// https://www.drupal.org/node/2302149
......@@ -409,7 +409,7 @@ protected function preSave(array &$link, array $original) {
unset($fields['mlid']);
// Cast Booleans to int, if needed.
$fields['hidden'] = (int) $fields['hidden'];
$fields['enabled'] = (int) $fields['enabled'];
$fields['expanded'] = (int) $fields['expanded'];
return $fields;
}
......@@ -599,7 +599,7 @@ protected function updateParentalStatus(array $link) {
$query
->condition('menu_name', $link['menu_name'])
->condition('parent', $link['parent'])
->condition('hidden', 0);
->condition('enabled', 1);
$parent_has_children = ((bool) $query->execute()->fetchField()) ? 1 : 0;
$this->connection->update($this->table, $this->options)
......@@ -781,7 +781,7 @@ public function getExpanded($menu_name, array $parents) {
$query->condition('menu_name', $menu_name);
$query->condition('expanded', 1);
$query->condition('has_children', 1);
$query->condition('hidden', 0);
$query->condition('enabled', 1);
$query->condition('parent', $parents, 'IN');
$query->condition('id', $parents, 'NOT IN');
$result = $this->safeExecuteSelect($query)->fetchAllKeyed(0, 0);
......@@ -997,7 +997,7 @@ public function loadSubtreeData($id, $max_relative_depth = NULL) {
return $tree;
}
$parameters = new MenuTreeParameters();
$parameters->setRoot($id)->excludeHiddenLinks();
$parameters->setRoot($id)->onlyEnabledLinks();
return $this->loadTreeData($root['menu_name'], $parameters);
}
......@@ -1057,7 +1057,7 @@ public function getAllChildIds($id) {
*/
public function loadAllChildren($id, $max_relative_depth = NULL) {
$parameters = new MenuTreeParameters();
$parameters->setRoot($id)->excludeRoot()->setMaxDepth($max_relative_depth)->excludeHiddenLinks();
$parameters->setRoot($id)->excludeRoot()->setMaxDepth($max_relative_depth)->onlyEnabledLinks();
$links = $this->loadLinks(NULL, $parameters);
foreach ($links as $id => $link) {
$links[$id] = $this->prepareLink($link);
......@@ -1289,11 +1289,11 @@ protected static function schemaDefinition() {
'not null' => TRUE,
'default' => 'system',
),
'hidden' => array(
'description' => 'A flag for whether the link should be rendered in menus. (1 = a disabled menu item that may be shown on admin screens, 0 = a normal, visible link)',
'enabled' => array(
'description' => 'A flag for whether the link should be rendered in menus. (0 = a disabled menu item that may be shown on admin screens, 1 = a normal, visible link)',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'default' => 1,
'size' => 'small',
),
'discovered' => array(
......@@ -1324,7 +1324,7 @@ protected static function schemaDefinition() {
'serialize' => TRUE,
),
'has_children' => array(
'description' => 'Flag indicating whether any non-hidden links have this link as a parent (1 = children exist, 0 = no children).',
'description' => 'Flag indicating whether any enabled links have this link as a parent (1 = enabled children exist, 0 = no enabled children).',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
......
......@@ -149,11 +149,11 @@ public function delete($id);
public function loadTreeData($menu_name, MenuTreeParameters $parameters);
/**
* Loads all the visible menu links that are below the given ID.
* Loads all the enabled menu links that are below the given ID.
*
* The returned links are not ordered, and visible children will be included
* even if they have a hidden parent or ancestor so would not normally appear
* in a rendered tree.
* even if they have parent that is not enabled or ancestor so would not
* normally appear in a rendered tree.
*
* @param string $id
* The parent menu link ID.
......@@ -161,7 +161,7 @@ public function loadTreeData($menu_name, MenuTreeParameters $parameters);
* The maximum relative depth of the children relative to the passed parent.
*
* @return array
* An array of visible (not hidden) link definitions, keyed by ID.
* An array of enabled link definitions, keyed by ID.
*/
public function loadAllChildren($id, $max_relative_depth = NULL);
......
......@@ -129,7 +129,7 @@ public function saveOverride($id, array $definition) {
'parent' => 1,
'weight' => 1,
'expanded' => 1,
'hidden' => 1,
'enabled' => 1,
);
// Filter the overrides to only those that are expected.
$definition = array_intersect_key($definition, $expected);
......
......@@ -32,7 +32,7 @@ public function reload();
* - weight
* - menu_name
* - expanded
* - hidden
* - enabled
* or NULL if there is no override for the given ID.
*/
public function loadOverride($id);
......@@ -77,7 +77,7 @@ public function loadMultipleOverrides(array $ids);
* - parent
* - weight
* - expanded
* - hidden
* - enabled
*
* @return array
* A list of properties which got saved.
......
......@@ -6,4 +6,4 @@ book.admin:
book.render:
title: Books
route_name: book.render
hidden: 1
enabled: 0
......@@ -7,4 +7,4 @@ contact.site_page:
title: Contact
route_name: contact.site_page
menu_name: footer
hidden: 1
enabled: 0
filter.tips_all:
title: 'Compose tips'
hidden: 1
enabled: 0
route_name: filter.tips_all
filter.admin_overview:
title: 'Text formats'
......
......@@ -157,8 +157,8 @@ public function getPluginId() {
/**
* {@inheritdoc}
*/
public function isHidden() {
return (bool) $this->get('hidden')->value;
public function isEnabled() {
return (bool) $this->get('enabled')->value;
}
/**
......@@ -204,7 +204,7 @@ protected function getPluginDefinition() {
$definition['id'] = $this->getPluginId();
$definition['metadata'] = array('entity_id' => $this->id());
$definition['form_class'] = '\Drupal\menu_link_content\Form\MenuLinkContentForm';
$definition['hidden'] = $this->isHidden() ? 1 : 0;
$definition['enabled'] = $this->isEnabled() ? 1 : 0;
$definition['expanded'] = $this->isExpanded() ? 1 : 0;
$definition['provider'] = 'menu_link_content';
$definition['discovered'] = 0;
......@@ -366,13 +366,19 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
'weight' => 0,
));
// @todo We manually create a form element for this, since the form logic is
// is inverted to show enabled. Flip this to a status field and use the
// normal entity Boolean widget. https://www.drupal.org/node/2305707
$fields['hidden'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Hidden'))
->setDescription(t('A flag for whether the link should be hidden in menus or rendered normally.'))
->setSetting('default_value', FALSE);
$fields['enabled'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Enabled'))
->setDescription(t('A flag for whether the link should be enabled in menus or hidden.'))
->setSetting('default_value', TRUE)
->setDisplayOptions('view', array(
'label' => 'hidden',
'type' => 'boolean',
'weight' => 0,
))
->setDisplayOptions('form', array(
'settings' => array('display_label' => TRUE),
'weight' => 0,
));
$fields['langcode'] = BaseFieldDefinition::create('language')
->setLabel(t('Language code'))
......
......@@ -213,7 +213,7 @@ protected function extractUrl($url) {
public function extractFormValues(array &$form, FormStateInterface $form_state) {
$new_definition = array();
$new_definition['expanded'] = !$form_state->isValueEmpty(array('expanded', 'value')) ? 1 : 0;
$new_definition['hidden'] = $form_state->isValueEmpty('enabled') ? 1 : 0;
$new_definition['enabled'] = !$form_state->isValueEmpty(array('enabled', 'value')) ? 1 : 0;
list($menu_name, $parent) = explode(':', $form_state->getValue('menu_parent'), 2);
if (!empty($menu_name)) {
$new_definition['menu_name'] = $menu_name;
......@@ -294,14 +294,6 @@ public function form(array $form, FormStateInterface $form_state) {
'#access' => !empty($language_configuration['language_show']),
);
$form['enabled'] = array(
'#type' => 'checkbox',
'#title' => $this->t('Enable menu link'),
'#description' => $this->t('Menu links that are not enabled will not be listed in any menu.'),
'#default_value' => !$this->entity->isHidden(),
'#weight' => 0,
);
$default = $this->entity->getMenuName() . ':' . $this->entity->getParentId();
$form['menu_parent'] = $this->menuParentSelector->parentSelectElement($default, $this->entity->getPluginId());
$form['menu_parent']['#weight'] = 10;
......@@ -342,7 +334,7 @@ public function buildEntity(array $form, FormStateInterface $form_state) {
$entity->parent->value = $new_definition['parent'];
$entity->menu_name->value = $new_definition['menu_name'];
$entity->hidden->value = (bool) $new_definition['hidden'];
$entity->enabled->value = (bool) $new_definition['enabled'];
$entity->expanded->value = $new_definition['expanded'];
$entity->url->value = $new_definition['url'];
......
......@@ -118,12 +118,12 @@ public function getDescription();
public function getPluginId();
/**
* Returns whether the menu link is marked as hidden.
* Returns whether the menu link is marked as enabled.
*
* @return bool
* TRUE if is not enabled, otherwise FALSE.
* TRUE if is enabled, otherwise FALSE.
*/
public function isHidden();
public function isEnabled();
/**
* Returns whether the menu link is marked as always expanded.
......
......@@ -37,7 +37,7 @@ class MenuLinkContent extends MenuLinkBase implements ContainerFactoryPluginInte
'parent' => 1,
'weight' => 1,
'expanded' => 1,
'hidden' => 1,
'enabled' => 1,
'title' => 1,
'description' => 1,
'route_name' => 1,
......
......@@ -197,7 +197,7 @@ function menu_ui_node_save(EntityInterface $node) {
if (trim($definition['title'])) {
if (!empty($definition['entity_id'])) {
$entity = entity_load('menu_link_content', $definition['entity_id']);
$entity->hidden->value = 0;
$entity->enabled->value = 1;
$entity->title->value = trim($definition['title']);
$entity->description->value = trim($definition['description']);
$entity->menu_name->value = $definition['menu_name'];
......@@ -214,7 +214,7 @@ function menu_ui_node_save(EntityInterface $node) {
'menu_name' => $definition['menu_name'],
'parent' => $definition['parent'],
'weight' => isset($definition['weight']) ? $definition['weight'] : 0,
'hidden' => 0,
'enabled' => 1,
'bundle' => 'menu_link_content',
'langcode' => $node->getUntranslated()->language()->id,
));
......
......@@ -265,9 +265,9 @@ protected function buildOverviewTreeForm($tree, $delta) {
if ($link) {
$id = 'menu_plugin_id:' . $link->getPluginId();
$form[$id]['#item'] = $element;
$form[$id]['#attributes'] = $link->isHidden() ? array('class' => array('menu-disabled')) : array('class' => array('menu-enabled'));
$form[$id]['#attributes'] = $link->isEnabled() ? array('class' => array('menu-enabled')) : array('class' => array('menu-disabled'));
$form[$id]['title']['#markup'] = $this->linkGenerator->generateFromUrl($link->getTitle(), $link->getUrlObject(), $link->getOptions());
if ($link->isHidden()) {
if (!$link->isEnabled()) {
$form[$id]['title']['#markup'] .= ' (' . $this->t('disabled') . ')';
}
elseif (($url = $link->getUrlObject()) && !$url->isExternal() && $url->getRouteName() == 'user.page') {
......@@ -278,7 +278,7 @@ protected function buildOverviewTreeForm($tree, $delta) {
'#type' => 'checkbox',
'#title' => $this->t('Enable @title menu link', array('@title' => $link->getTitle())),
'#title_display' => 'invisible',
'#default_value' => !$link->isHidden(),
'#default_value' => $link->isEnabled(),
);
$form[$id]['weight'] = array(
'#type' => 'weight',
......@@ -378,13 +378,7 @@ protected function submitOverviewForm(array $complete_form, FormStateInterface $
// Update any fields that have changed in this menu item.
foreach ($fields as $field) {
if ($element[$field]['#value'] != $element[$field]['#default_value']) {
// Hidden is a special case, the form value needs to be reversed.
if ($field == 'enabled') {
$updated_values['hidden'] = $element['enabled']['#value'] ? 0 : 1;
}
else {
$updated_values[$field] = $element[$field]['#value'];
}
$updated_values[$field] = $element[$field]['#value'];
}
}
if ($updated_values) {
......
......@@ -400,7 +400,7 @@ function doMenuTests() {
$item5->save();
// Verify in the database.
$this->assertMenuLink($item1->getPluginId(), array('hidden' => 0));
$this->assertMenuLink($item1->getPluginId(), array('enabled' => 1));
// Add an external link.
$item7 = $this->addMenuLink('', 'http://drupal.org', $menu_name);
......@@ -529,7 +529,7 @@ function addMenuLink($parent = '', $path = '<front>', $menu_name = 'tools', $exp
'url' => $path,
'title[0][value]' => $title,
'description[0][value]' => '',
'enabled' => 1,
'enabled[value]' => 1,
'expanded[value]' => $expanded,
'menu_parent' => $menu_name . ':' . $parent,
'weight[0][value]' => $weight,
......@@ -711,12 +711,12 @@ function toggleMenuLink(MenuLinkContent $item) {
*/
function disableMenuLink(MenuLinkContent $item) {
$mlid = $item->id();
$edit['enabled'] = FALSE;
$edit['enabled[value]'] = FALSE;
$this->drupalPostForm("admin/structure/menu/item/$mlid/edit", $edit, t('Save'));
// Unlike most other modules, there is no confirmation message displayed.
// Verify in the database.
$this->assertMenuLink($item->getPluginId(), array('hidden' => 1));
$this->assertMenuLink($item->getPluginId(), array('enabled' => 0));
}
/**
......@@ -727,11 +727,11 @@ function disableMenuLink(MenuLinkContent $item) {
*/
function enableMenuLink(MenuLinkContent $item) {
$mlid = $item->id();
$edit['enabled'] = TRUE;
$edit['enabled[value]'] = TRUE;
$this->drupalPostForm("admin/structure/menu/item/$mlid/edit", $edit, t('Save'));
// Verify in the database.
$this->assertMenuLink($item->getPluginId(), array('hidden' => 0));
$this->assertMenuLink($item->getPluginId(), array('enabled' => 1));
}
/**
......
......@@ -68,6 +68,11 @@ function assertMenuLink($menu_plugin_id, array $expected_item) {
unset($expected_item['langcode']);
}
if (isset($expected_item['enabled']) && $entity) {
$this->assertEqual($entity->enabled->value, $expected_item['enabled']);
unset($expected_item['enabled']);
}
foreach ($expected_item as $key => $value) {
$this->assertTrue(isset($definition[$key]));
$this->assertEqual($definition[$key], $value);
......
search.view:
title: Search
route_name: search.view
hidden: 1
enabled: 0
search.settings:
title: 'Search pages'
parent: system.admin_config_search
......
......@@ -120,7 +120,7 @@ public function overview($link_id) {
}
// Load all menu links below it.
$parameters = new MenuTreeParameters();
$parameters->setRoot($link_id)->excludeRoot()->setTopLevelOnly()->excludeHiddenLinks();
$parameters->setRoot($link_id)->excludeRoot()->setTopLevelOnly()->onlyEnabledLinks();
$tree = $this->menuLinkTree->load(NULL, $parameters);
$manipulators = array(
array('callable' => 'menu.default_tree_manipulators:checkAccess'),
......
......@@ -217,7 +217,7 @@ public function getAdminBlock(MenuLinkInterface $instance) {
// Only find the children of this link.
$link_id = $instance->getPluginId();
$parameters = new MenuTreeParameters();
$parameters->setRoot($link_id)->excludeRoot()->setTopLevelOnly()->excludeHiddenLinks();
$parameters->setRoot($link_id)->excludeRoot()->setTopLevelOnly()->onlyEnabledLinks();
$tree = $this->menuTree->load(NULL, $parameters);
$manipulators = array(
array('callable' => 'menu.default_tree_manipulators:checkAccess'),
......
......@@ -170,7 +170,7 @@ function testBreadCrumbs() {
'type' => $type,
'title' => $title,
'menu' => array(
'hidden' => 0,
'enabled' => 1,
'title' => 'Parent ' . $title,
'description' => '',
'menu_name' => $menu,
......@@ -243,6 +243,7 @@ function testBreadCrumbs() {
'title[0][value]' => "$name link",
'url' => "taxonomy/term/{$term->id()}",
'menu_parent' => "$menu:{$parent_mlid}",
'enabled[value]' => 1,
);
$this->drupalPostForm("admin/structure/menu/manage/$menu/add", $edit, t('Save'));
$menu_links = entity_load_multiple_by_properties('menu_link_content', array('title' => $edit['title[0][value]'], 'route_name' => 'taxonomy.term_page', 'route_parameters' => serialize(array('taxonomy_term' => $term->id()))));
......
......@@ -181,21 +181,21 @@ public function testMenuLinkMoving() {
}
/**
* Tests with hidden child links.
* Tests with disabled child links.
*/
public function testMenuHiddenChildLinks() {
public function testMenuDisabledChildLinks() {
// Add some links with parent on the previous one and test some values.
// <tools>
// - test1
// -- test2 (hidden)
// -- test2 (disabled)
$this->addMenuLink('test1', '');
$this->assertMenuLink('test1', array('has_children' => 0, 'depth' => 1));
$this->addMenuLink('test2', 'test1', '<front>', array(), 'tools', array('hidden' => 1));
$this->addMenuLink('test2', 'test1', '<front>', array(), 'tools', array('enabled' => 0));
// The 1st link does not have any visible children, so has_children is 0.
$this->assertMenuLink('test1', array('has_children' => 0, 'depth' => 1));
$this->assertMenuLink('test2', array('has_children' => 0, 'depth' => 2, 'hidden' => 1), array('test1'));
$this->assertMenuLink('test2', array('has_children' => 0, 'depth' => 2, 'enabled' => 0), array('test1'));
// Add more links with parent on the previous one.
// <footer>
......@@ -203,7 +203,7 @@ public function testMenuHiddenChildLinks() {
// ===============
// <tools>
// - test1
// -- test2 (hidden)
// -- test2 (disabled)
// --- test3
// ---- test4
// ----- test5
......@@ -367,7 +367,7 @@ protected function moveMenuLink($id, $new_parent) {
* @param array $parents
* An ordered array of the IDs of the menu links that are the parents.
* @param array $children
* Array of child IDs that are visible (hidden == 0).
* Array of child IDs that are visible (enabled == 1).
*/
protected function assertMenuLink($id, array $expected_properties, array $parents = array(), array $children = array()) {
$query = $this->connection->select('menu_tree');
......
......@@ -128,7 +128,7 @@ protected function getTopLevelMenuLinks() {
// The system.admin link is normally the parent of all top-level admin links.
$parameters = new MenuTreeParameters();
$parameters->setRoot('system.admin')->excludeRoot()->setTopLevelOnly()->excludeHiddenLinks();
$parameters->setRoot('system.admin')->excludeRoot()->setTopLevelOnly()->onlyEnabledLinks();
$tree = $menu_tree->load(NULL, $parameters);
$manipulators = array(
array('callable' => 'menu.default_tree_manipulators:checkAccess'),
......
......@@ -1448,7 +1448,7 @@ function system_get_module_admin_tasks($module, array $info) {
if (!isset($tree)) {
$parameters = new MenuTreeParameters();
$parameters->setRoot('system.admin')->excludeRoot()->excludeHiddenLinks();
$parameters->setRoot('system.admin')->excludeRoot()->onlyEnabledLinks();
$tree = $menu_tree->load('system.admin', $parameters);
$manipulators = array(
array('callable' => 'menu.default_tree_manipulators:checkAccess'),
......
......@@ -417,7 +417,7 @@ function toolbar_prerender_toolbar_administration_tray(array $element) {
$menu_tree = \Drupal::menuTree();
// Render the top-level administration menu links.
$parameters = new MenuTreeParameters();
$parameters->setRoot('system.admin')->excludeRoot()->setTopLevelOnly()->excludeHiddenLinks();
$parameters->setRoot('system.admin')->excludeRoot()->setTopLevelOnly()->onlyEnabledLinks();
$tree = $menu_tree->load(NULL, $parameters);
$manipulators = array(
array('callable' => 'menu.default_tree_manipulators:checkAccess'),
......@@ -475,7 +475,7 @@ function toolbar_menu_navigation_links(array $tree) {
function toolbar_get_rendered_subtrees() {
$menu_tree = \Drupal::menuTree();
$parameters = new MenuTreeParameters();
$parameters->setRoot('system.admin')->excludeRoot()->setMaxDepth(3)->excludeHiddenLinks();
$parameters->setRoot('system.admin')->excludeRoot()->setMaxDepth(3)->onlyEnabledLinks();
$tree = $menu_tree->load(NULL, $parameters);
$manipulators = array(
array('callable' => 'menu.default_tree_manipulators:checkAccess'),
......
......@@ -17,14 +17,14 @@ class MyAccountMenuLink extends MenuLinkDefault {
/**
* {@inheritdoc}
*/
public function isHidden() {
public function isEnabled() {
// The path 'user' must be accessible for anonymous users, but only visible
// for authenticated users. Authenticated users should see "My account", but
// anonymous users should not see it at all.
// @todo Re-write this as a link to user.view with dynamic route parameters
// to affect access since hidden should not be dynamic.
// https://www.drupal.org/node/2306991
return $this->pluginDefinition['hidden'] || \Drupal::currentUser()->isAnonymous();
return $this->pluginDefinition['enabled'] && !\Drupal::currentUser()->isAnonymous();
}
/**
......
......@@ -70,7 +70,7 @@ function testSecondaryMenu() {
$tree = $menu_tree->transform($tree, $manipulators);
$this->assertEqual(count($tree), 1, 'The secondary links menu contains only one menu link.');
$element = reset($tree);
$this->assertTrue($element->link->isHidden(), 'The menu link is hidden.');
$this->assertFalse($element->link->isEnabled(), 'The menu link is disabled.');
}
/**
......
......@@ -28,7 +28,7 @@ class ViewsMenuLink extends MenuLinkBase implements ContainerFactoryPluginInterf
'parent' => 1,
'weight' => 1,
'expanded' => 1,
'hidden' => 1,
'enabled' => 1,
'title' => 1,
'description' => 1,
'metadata' => 1,
......
......@@ -46,7 +46,7 @@ function standard_install() {
// Enable the Contact link in the footer menu.
/** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */
$menu_link_manager = \Drupal::service('plugin.manager.menu.link');
$menu_link_manager->updateDefinition('contact.site_page', array('hidden' => 0));
$menu_link_manager->updateDefinition('contact.site_page', array('enabled' => 1));
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access site-wide contact form'));
user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array('access site-wide contact form'));
......
......@@ -115,14 +115,14 @@ public function testAddCondition() {
}
/**
* Tests excludeHiddenLinks().
* Tests onlyEnabledLinks().
*
* @covers ::excludeHiddenLinks
* @covers ::onlyEnabledLinks
*/
public function testExcludeHiddenLinks() {
public function testOnlyEnabledLinks() {
$parameters = new MenuTreeParameters();
$parameters->excludeHiddenLinks();
$this->assertEquals(0, $parameters->conditions['hidden']);