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: ...@@ -22,6 +22,6 @@ menu_link.static.overrides:
expanded: expanded:
type: boolean type: boolean
label: 'Expanded' label: 'Expanded'
hidden: enabled:
type: boolean type: boolean
label: 'Hidden' label: 'Enabled'
...@@ -124,7 +124,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta ...@@ -124,7 +124,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
'#type' => 'checkbox', '#type' => 'checkbox',
'#title' => $this->t('Enable menu link'), '#title' => $this->t('Enable menu link'),
'#description' => $this->t('Menu links that are not enabled will not be listed in any menu.'), '#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( $form['expanded'] = array(
...@@ -158,7 +158,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta ...@@ -158,7 +158,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
*/ */
public function extractFormValues(array &$form, FormStateInterface $form_state) { public function extractFormValues(array &$form, FormStateInterface $form_state) {
$new_definition = array(); $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['weight'] = (int) $form_state->getValue('weight');
$new_definition['expanded'] = $form_state->getValue('expanded') ? 1 : 0; $new_definition['expanded'] = $form_state->getValue('expanded') ? 1 : 0;
list($menu_name, $parent) = explode(':', $form_state->getValue('menu_parent'), 2); list($menu_name, $parent) = explode(':', $form_state->getValue('menu_parent'), 2);
......
...@@ -61,8 +61,8 @@ public function getParent() { ...@@ -61,8 +61,8 @@ public function getParent() {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function isHidden() { public function isEnabled() {
return (bool) $this->pluginDefinition['hidden']; return (bool) $this->pluginDefinition['enabled'];
} }
/** /**
......
...@@ -23,7 +23,7 @@ class MenuLinkDefault extends MenuLinkBase implements ContainerFactoryPluginInte ...@@ -23,7 +23,7 @@ class MenuLinkDefault extends MenuLinkBase implements ContainerFactoryPluginInte
'parent' => 1, 'parent' => 1,
'weight' => 1, 'weight' => 1,
'expanded' => 1, 'expanded' => 1,
'hidden' => 1, 'enabled' => 1,
); );
/** /**
......
...@@ -64,12 +64,12 @@ public function getProvider(); ...@@ -64,12 +64,12 @@ public function getProvider();
public function getParent(); public function getParent();
/** /**
* Returns whether the menu link is hidden. * Returns whether the menu link is enabled (not hidden).
* *
* @return bool * @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. * Returns whether the child menu links should always been shown.
......
...@@ -58,7 +58,7 @@ class MenuLinkManager implements MenuLinkManagerInterface { ...@@ -58,7 +58,7 @@ class MenuLinkManager implements MenuLinkManagerInterface {
// The default link options. // The default link options.
'options' => array(), 'options' => array(),
'expanded' => 0, 'expanded' => 0,
'hidden' => 0, 'enabled' => 1,
// The name of the module providing this link. // The name of the module providing this link.
'provider' => '', 'provider' => '',
'metadata' => array(), 'metadata' => array(),
......
...@@ -205,7 +205,7 @@ public function build(array $tree) { ...@@ -205,7 +205,7 @@ public function build(array $tree) {
/** @var \Drupal\Core\Menu\MenuLinkInterface $link */ /** @var \Drupal\Core\Menu\MenuLinkInterface $link */
$link = $data->link; $link = $data->link;
// Generally we only deal with visible links, but just in case. // Generally we only deal with visible links, but just in case.
if ($link->isHidden()) { if (!$link->isEnabled()) {
continue; continue;
} }
// Set a class for the <li>-tag. Only set 'expanded' class if the link // 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, ...@@ -143,7 +143,7 @@ protected function parentSelectOptionsTreeWalk(array $tree, $menu_name, $indent,
$link = $element->link; $link = $element->link;
if ($link->getPluginId() != $exclude) { if ($link->getPluginId() != $exclude) {
$title = $indent . ' ' . Unicode::truncate($link->getTitle(), 30, TRUE, FALSE); $title = $indent . ' ' . Unicode::truncate($link->getTitle(), 30, TRUE, FALSE);
if ($link->isHidden()) { if (!$link->isEnabled()) {
$title .= ' (' . $this->t('disabled') . ')'; $title .= ' (' . $this->t('disabled') . ')';
} }
$options[$menu_name . ':' . $link->getPluginId()] = $title; $options[$menu_name . ':' . $link->getPluginId()] = $title;
......
...@@ -184,12 +184,12 @@ public function addCondition($definition_field, $value, $operator = NULL) { ...@@ -184,12 +184,12 @@ public function addCondition($definition_field, $value, $operator = NULL) {
} }
/** /**
* Excludes hidden links. * Excludes links that are not enabled.
* *
* @return $this * @return $this
*/ */
public function excludeHiddenLinks() { public function onlyEnabledLinks() {
$this->addCondition('hidden', 0); $this->addCondition('enabled', 1);
return $this; return $this;
} }
......
...@@ -94,7 +94,7 @@ class MenuTreeStorage implements MenuTreeStorageInterface { ...@@ -94,7 +94,7 @@ class MenuTreeStorage implements MenuTreeStorageInterface {
'weight', 'weight',
'options', 'options',
'expanded', 'expanded',
'hidden', 'enabled',
'provider', 'provider',
'metadata', 'metadata',
'class', 'class',
...@@ -384,7 +384,7 @@ protected function preSave(array &$link, array $original) { ...@@ -384,7 +384,7 @@ protected function preSave(array &$link, array $original) {
// and fill parents based on the parent link. // and fill parents based on the parent link.
else { else {
// @todo We want to also check $original['has_children'] here, but that // @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 // has_children is really just the rendering hint. So, we either need
// to define another column (has_any_children), or do the extra query. // to define another column (has_any_children), or do the extra query.
// https://www.drupal.org/node/2302149 // https://www.drupal.org/node/2302149
...@@ -409,7 +409,7 @@ protected function preSave(array &$link, array $original) { ...@@ -409,7 +409,7 @@ protected function preSave(array &$link, array $original) {
unset($fields['mlid']); unset($fields['mlid']);
// Cast Booleans to int, if needed. // Cast Booleans to int, if needed.
$fields['hidden'] = (int) $fields['hidden']; $fields['enabled'] = (int) $fields['enabled'];
$fields['expanded'] = (int) $fields['expanded']; $fields['expanded'] = (int) $fields['expanded'];
return $fields; return $fields;
} }
...@@ -599,7 +599,7 @@ protected function updateParentalStatus(array $link) { ...@@ -599,7 +599,7 @@ protected function updateParentalStatus(array $link) {
$query $query
->condition('menu_name', $link['menu_name']) ->condition('menu_name', $link['menu_name'])
->condition('parent', $link['parent']) ->condition('parent', $link['parent'])
->condition('hidden', 0); ->condition('enabled', 1);
$parent_has_children = ((bool) $query->execute()->fetchField()) ? 1 : 0; $parent_has_children = ((bool) $query->execute()->fetchField()) ? 1 : 0;
$this->connection->update($this->table, $this->options) $this->connection->update($this->table, $this->options)
...@@ -781,7 +781,7 @@ public function getExpanded($menu_name, array $parents) { ...@@ -781,7 +781,7 @@ public function getExpanded($menu_name, array $parents) {
$query->condition('menu_name', $menu_name); $query->condition('menu_name', $menu_name);
$query->condition('expanded', 1); $query->condition('expanded', 1);
$query->condition('has_children', 1); $query->condition('has_children', 1);
$query->condition('hidden', 0); $query->condition('enabled', 1);
$query->condition('parent', $parents, 'IN'); $query->condition('parent', $parents, 'IN');
$query->condition('id', $parents, 'NOT IN'); $query->condition('id', $parents, 'NOT IN');
$result = $this->safeExecuteSelect($query)->fetchAllKeyed(0, 0); $result = $this->safeExecuteSelect($query)->fetchAllKeyed(0, 0);
...@@ -997,7 +997,7 @@ public function loadSubtreeData($id, $max_relative_depth = NULL) { ...@@ -997,7 +997,7 @@ public function loadSubtreeData($id, $max_relative_depth = NULL) {
return $tree; return $tree;
} }
$parameters = new MenuTreeParameters(); $parameters = new MenuTreeParameters();
$parameters->setRoot($id)->excludeHiddenLinks(); $parameters->setRoot($id)->onlyEnabledLinks();
return $this->loadTreeData($root['menu_name'], $parameters); return $this->loadTreeData($root['menu_name'], $parameters);
} }
...@@ -1057,7 +1057,7 @@ public function getAllChildIds($id) { ...@@ -1057,7 +1057,7 @@ public function getAllChildIds($id) {
*/ */
public function loadAllChildren($id, $max_relative_depth = NULL) { public function loadAllChildren($id, $max_relative_depth = NULL) {
$parameters = new MenuTreeParameters(); $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); $links = $this->loadLinks(NULL, $parameters);
foreach ($links as $id => $link) { foreach ($links as $id => $link) {
$links[$id] = $this->prepareLink($link); $links[$id] = $this->prepareLink($link);
...@@ -1289,11 +1289,11 @@ protected static function schemaDefinition() { ...@@ -1289,11 +1289,11 @@ protected static function schemaDefinition() {
'not null' => TRUE, 'not null' => TRUE,
'default' => 'system', 'default' => 'system',
), ),
'hidden' => array( 'enabled' => 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)', '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', 'type' => 'int',
'not null' => TRUE, 'not null' => TRUE,
'default' => 0, 'default' => 1,
'size' => 'small', 'size' => 'small',
), ),
'discovered' => array( 'discovered' => array(
...@@ -1324,7 +1324,7 @@ protected static function schemaDefinition() { ...@@ -1324,7 +1324,7 @@ protected static function schemaDefinition() {
'serialize' => TRUE, 'serialize' => TRUE,
), ),
'has_children' => array( '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', 'type' => 'int',
'not null' => TRUE, 'not null' => TRUE,
'default' => 0, 'default' => 0,
......
...@@ -149,11 +149,11 @@ public function delete($id); ...@@ -149,11 +149,11 @@ public function delete($id);
public function loadTreeData($menu_name, MenuTreeParameters $parameters); 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 * 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 * even if they have parent that is not enabled or ancestor so would not
* in a rendered tree. * normally appear in a rendered tree.
* *
* @param string $id * @param string $id
* The parent menu link ID. * The parent menu link ID.
...@@ -161,7 +161,7 @@ public function loadTreeData($menu_name, MenuTreeParameters $parameters); ...@@ -161,7 +161,7 @@ public function loadTreeData($menu_name, MenuTreeParameters $parameters);
* The maximum relative depth of the children relative to the passed parent. * The maximum relative depth of the children relative to the passed parent.
* *
* @return array * @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); public function loadAllChildren($id, $max_relative_depth = NULL);
......
...@@ -129,7 +129,7 @@ public function saveOverride($id, array $definition) { ...@@ -129,7 +129,7 @@ public function saveOverride($id, array $definition) {
'parent' => 1, 'parent' => 1,
'weight' => 1, 'weight' => 1,
'expanded' => 1, 'expanded' => 1,
'hidden' => 1, 'enabled' => 1,
); );
// Filter the overrides to only those that are expected. // Filter the overrides to only those that are expected.
$definition = array_intersect_key($definition, $expected); $definition = array_intersect_key($definition, $expected);
......
...@@ -32,7 +32,7 @@ public function reload(); ...@@ -32,7 +32,7 @@ public function reload();
* - weight * - weight
* - menu_name * - menu_name
* - expanded * - expanded
* - hidden * - enabled
* or NULL if there is no override for the given ID. * or NULL if there is no override for the given ID.
*/ */
public function loadOverride($id); public function loadOverride($id);
...@@ -77,7 +77,7 @@ public function loadMultipleOverrides(array $ids); ...@@ -77,7 +77,7 @@ public function loadMultipleOverrides(array $ids);
* - parent * - parent
* - weight * - weight
* - expanded * - expanded
* - hidden * - enabled
* *
* @return array * @return array
* A list of properties which got saved. * A list of properties which got saved.
......
...@@ -6,4 +6,4 @@ book.admin: ...@@ -6,4 +6,4 @@ book.admin:
book.render: book.render:
title: Books title: Books
route_name: book.render route_name: book.render
hidden: 1 enabled: 0
...@@ -7,4 +7,4 @@ contact.site_page: ...@@ -7,4 +7,4 @@ contact.site_page:
title: Contact title: Contact
route_name: contact.site_page route_name: contact.site_page
menu_name: footer menu_name: footer
hidden: 1 enabled: 0
filter.tips_all: filter.tips_all:
title: 'Compose tips' title: 'Compose tips'
hidden: 1 enabled: 0
route_name: filter.tips_all route_name: filter.tips_all
filter.admin_overview: filter.admin_overview:
title: 'Text formats' title: 'Text formats'
......
...@@ -157,8 +157,8 @@ public function getPluginId() { ...@@ -157,8 +157,8 @@ public function getPluginId() {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function isHidden() { public function isEnabled() {
return (bool) $this->get('hidden')->value; return (bool) $this->get('enabled')->value;
} }
/** /**
...@@ -204,7 +204,7 @@ protected function getPluginDefinition() { ...@@ -204,7 +204,7 @@ protected function getPluginDefinition() {
$definition['id'] = $this->getPluginId(); $definition['id'] = $this->getPluginId();
$definition['metadata'] = array('entity_id' => $this->id()); $definition['metadata'] = array('entity_id' => $this->id());
$definition['form_class'] = '\Drupal\menu_link_content\Form\MenuLinkContentForm'; $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['expanded'] = $this->isExpanded() ? 1 : 0;
$definition['provider'] = 'menu_link_content'; $definition['provider'] = 'menu_link_content';
$definition['discovered'] = 0; $definition['discovered'] = 0;
...@@ -366,13 +366,19 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ...@@ -366,13 +366,19 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
'weight' => 0, 'weight' => 0,
)); ));
// @todo We manually create a form element for this, since the form logic is $fields['enabled'] = BaseFieldDefinition::create('boolean')
// is inverted to show enabled. Flip this to a status field and use the ->setLabel(t('Enabled'))
// normal entity Boolean widget. https://www.drupal.org/node/2305707 ->setDescription(t('A flag for whether the link should be enabled in menus or hidden.'))
$fields['hidden'] = BaseFieldDefinition::create('boolean') ->setSetting('default_value', TRUE)
->setLabel(t('Hidden')) ->setDisplayOptions('view', array(
->setDescription(t('A flag for whether the link should be hidden in menus or rendered normally.')) 'label' => 'hidden',
->setSetting('default_value', FALSE); 'type' => 'boolean',
'weight' => 0,
))
->setDisplayOptions('form', array(
'settings' => array('display_label' => TRUE),
'weight' => 0,
));
$fields['langcode'] = BaseFieldDefinition::create('language') $fields['langcode'] = BaseFieldDefinition::create('language')
->setLabel(t('Language code')) ->setLabel(t('Language code'))
......
...@@ -213,7 +213,7 @@ protected function extractUrl($url) { ...@@ -213,7 +213,7 @@ protected function extractUrl($url) {
public function extractFormValues(array &$form, FormStateInterface $form_state) { public function extractFormValues(array &$form, FormStateInterface $form_state) {
$new_definition = array(); $new_definition = array();
$new_definition['expanded'] = !$form_state->isValueEmpty(array('expanded', 'value')) ? 1 : 0; $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); list($menu_name, $parent) = explode(':', $form_state->getValue('menu_parent'), 2);
if (!empty($menu_name)) { if (!empty($menu_name)) {
$new_definition['menu_name'] = $menu_name; $new_definition['menu_name'] = $menu_name;
...@@ -294,14 +294,6 @@ public function form(array $form, FormStateInterface $form_state) { ...@@ -294,14 +294,6 @@ public function form(array $form, FormStateInterface $form_state) {
'#access' => !empty($language_configuration['language_show']), '#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(); $default = $this->entity->getMenuName() . ':' . $this->entity->getParentId();
$form['menu_parent'] = $this->menuParentSelector->parentSelectElement($default, $this->entity->getPluginId()); $form['menu_parent'] = $this->menuParentSelector->parentSelectElement($default, $this->entity->getPluginId());
$form['menu_parent']['#weight'] = 10; $form['menu_parent']['#weight'] = 10;
...@@ -342,7 +334,7 @@ public function buildEntity(array $form, FormStateInterface $form_state) { ...@@ -342,7 +334,7 @@ public function buildEntity(array $form, FormStateInterface $form_state) {
$entity->parent->value = $new_definition['parent']; $entity->parent->value = $new_definition['parent'];
$entity->menu_name->value = $new_definition['menu_name']; $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->expanded->value = $new_definition['expanded'];
$entity->url->value = $new_definition['url']; $entity->url->value = $new_definition['url'];
......
...@@ -118,12 +118,12 @@ public function getDescription(); ...@@ -118,12 +118,12 @@ public function getDescription();
public function getPluginId(); public function getPluginId();
/** /**
* Returns whether the menu link is marked as hidden. * Returns whether the menu link is marked as enabled.
* *
* @return bool * @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. * Returns whether the menu link is marked as always expanded.
......
...@@ -37,7 +37,7 @@ class MenuLinkContent extends MenuLinkBase implements ContainerFactoryPluginInte ...@@ -37,7 +37,7 @@ class MenuLinkContent extends MenuLinkBase implements ContainerFactoryPluginInte
'parent' => 1, 'parent' => 1,
'weight' => 1, 'weight' => 1,
'expanded' => 1, 'expanded' => 1,
'hidden' => 1, 'enabled' => 1,
'title' => 1, 'title' => 1,
'description' => 1, 'description' => 1,
'route_name' => 1, 'route_name' => 1,
......
...@@ -197,7 +197,7 @@ function menu_ui_node_save(EntityInterface $node) { ...@@ -197,7 +197,7 @@ function menu_ui_node_save(EntityInterface $node) {
if (trim($definition['title'])) { if (trim($definition['title'])) {
if (!empty($definition['entity_id'])) { if (!empty($definition['entity_id'])) {
$entity = entity_load('menu_link_content', $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->title->value = trim($definition['title']);
$entity->description->value = trim($definition['description']); $entity->description->value = trim($definition['description']);
$entity->menu_name->value = $definition['menu_name']; $entity->menu_name->value = $definition['menu_name'];
...@@ -214,7 +214,7 @@ function menu_ui_node_save(EntityInterface $node) { ...@@ -214,7 +214,7 @@ function menu_ui_node_save(EntityInterface $node) {
'menu_name' => $definition['menu_name'], 'menu_name' => $definition['menu_name'],
'parent' => $definition['parent'], 'parent' => $definition['parent'],
'weight' => isset($definition['weight']) ? $definition['weight'] : 0, 'weight' => isset($definition['weight']) ? $definition['weight'] : 0,
'hidden' => 0, 'enabled' => 1,
'bundle' => 'menu_link_content', 'bundle' => 'menu_link_content',
'langcode' => $node->getUntranslated()->language()->id, 'langcode' => $node->getUntranslated()->language()->id,
)); ));
......
...@@ -265,9 +265,9 @@ protected function buildOverviewTreeForm($tree, $delta) { ...@@ -265,9 +265,9 @@ protected function buildOverviewTreeForm($tree, $delta) {
if ($link) { if ($link) {
$id = 'menu_plugin_id:' . $link->getPluginId(); $id = 'menu_plugin_id:' . $link->getPluginId();
$form[$id]['#item'] = $element; $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()); $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') . ')'; $form[$id]['title']['#markup'] .= ' (' . $this->t('disabled') . ')';
} }
elseif (($url = $link->getUrlObject()) && !$url->isExternal() && $url->getRouteName() == 'user.page') { elseif (($url = $link->getUrlObject()) && !$url->isExternal() && $url->getRouteName() == 'user.page') {
...@@ -278,7 +278,7 @@ protected function buildOverviewTreeForm($tree, $delta) { ...@@ -278,7 +278,7 @@ protected function buildOverviewTreeForm($tree, $delta) {
'#type' => 'checkbox', '#type' => 'checkbox',
'#title' => $this->t('Enable @title menu link', array('@title' => $link->getTitle())), '#title' => $this->t('Enable @title menu link', array('@title' => $link->getTitle())),
'#title_display' => 'invisible', '#title_display' => 'invisible',
'#default_value' => !$link->isHidden(), '#default_value' => $link->isEnabled(),
); );
$form[$id]['weight'] = array( $form[$id]['weight'] = array(
'#type' => 'weight', '#type' => 'weight',
...@@ -378,13 +378,7 @@ protected function submitOverviewForm(array $complete_form, FormStateInterface $ ...@@ -378,13 +378,7 @@ protected function submitOverviewForm(array $complete_form, FormStateInterface $
// Update any fields that have changed in this menu item. // Update any fields that have changed in this menu item.
foreach ($fields as $field) { foreach ($fields as $field) {
if ($element[$field]['#value'] != $element[$field]['#default_value']) { if ($element[$field]['#value'] != $element[$field]['#default_value']) {
// Hidden is a special case, the form value needs to be reversed. $updated_values[$field] = $element[$field]['#value'];
if ($field == 'enabled') {
$updated_values['hidden'] = $element['enabled']['#value'] ? 0 : 1;
}
else {
$updated_values[$field] = $element[$field]['#value'];
}
} }
} }
if ($updated_values) { if ($updated_values) {
......
...@@ -400,7 +400,7 @@ function doMenuTests() { ...@@ -400,7 +400,7 @@ function doMenuTests() {
$item5->save(); $item5->save();
// Verify in the database. // Verify in the database.
$this->assertMenuLink($item1->getPluginId(), array('hidden' => 0)); $this->assertMenuLink($item1->getPluginId(), array('enabled' => 1));
// Add an external link. // Add an external link.
$item7 = $this->addMenuLink('', 'http://drupal.org', $menu_name); $item7 = $this->addMenuLink('', 'http://drupal.org', $menu_name);
...@@ -529,7 +529,7 @@ function addMenuLink($parent = '', $path = '<front>', $menu_name = 'tools', $exp ...@@ -529,7 +529,7 @@ function addMenuLink($parent = '', $path = '<front>', $menu_name = 'tools', $exp
'url' => $path, 'url' => $path,
'title[0][value]' => $title, 'title[0][value]' => $title,
'description[0][value]' => '', 'description[0][value]' => '',
'enabled' => 1, 'enabled[value]' => 1,
'expanded[value]' => $expanded, 'expanded[value]' => $expanded,
'menu_parent' => $menu_name . ':' . $parent, 'menu_parent' => $menu_name . ':' . $parent,
'weight[0][value]' => $weight, 'weight[0][value]' => $weight,
...@@ -711,12 +711,12 @@ function toggleMenuLink(MenuLinkContent $item) { ...@@ -711,12 +711,12 @@ function toggleMenuLink(MenuLinkContent $item) {
*/ */
function disableMenuLink(MenuLinkContent $item) { function disableMenuLink(MenuLinkContent $item) {
$mlid = $item->id(); $mlid = $item->id();
$edit['enabled'] = FALSE; $edit['enabled[value]'] = FALSE;
$this->drupalPostForm("admin/structure/menu/item/$mlid/edit", $edit, t('Save')); $this->drupalPostForm("admin/structure/menu/item/$mlid/edit", $edit, t('Save'));
// Unlike most other modules, there is no confirmation message displayed. // Unlike most other modules, there is no confirmation message displayed.
// Verify in the database. // 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) { ...@@ -727,11 +727,11 @@ function disableMenuLink(MenuLinkContent $item) {
*/ */
function enableMenuLink(MenuLinkContent $item) { function enableMenuLink(MenuLinkContent $item) {
$mlid = $item->id(); $mlid = $item->id();
$edit['enabled'] = TRUE; $edit['enabled[value]'] = TRUE;
$this->drupalPostForm("admin/structure/menu/item/$mlid/edit", $edit, t('Save')); $this->drupalPostForm("admin/structure/menu/item/$mlid/edit", $edit, t('Save'));
// Verify in the database. // Verify in the database.