diff --git a/core/lib/Drupal/Core/Menu/Form/MenuLinkDefaultForm.php b/core/lib/Drupal/Core/Menu/Form/MenuLinkDefaultForm.php index 442ac69..95278ec 100644 --- a/core/lib/Drupal/Core/Menu/Form/MenuLinkDefaultForm.php +++ b/core/lib/Drupal/Core/Menu/Form/MenuLinkDefaultForm.php @@ -89,7 +89,7 @@ public function setMenuLinkInstance(MenuLinkInterface $menu_link) { /** * {@inheritdoc} */ - public function buildEditForm(array &$form, array &$form_state) { + public function buildConfigurationForm(array $form, array &$form_state) { $form['#title'] = $this->t('Edit menu link %title', array('%title' => $this->menuLink->getTitle())); $provider = $this->menuLink->getProvider(); @@ -122,7 +122,7 @@ public function buildEditForm(array &$form, array &$form_state) { '#max' => $delta, '#default_value' => $this->menuLink->getWeight(), '#title' => $this->t('Weight'), - '#description' => $this->t('Link weight among links in the same menu at the same depth.'), + '#description' => $this->t('Optional. In the menu, the links with high weight will sink and links with a low weight will be positioned nearer the top.'), ); $options = $this->menuTree->getParentSelectOptions($this->menuLink->getPluginId()); @@ -165,13 +165,13 @@ public function extractFormValues(array &$form, array &$form_state) { /** * {@inheritdoc} */ - public function validateEditForm(array &$form, array &$form_state) { + public function validateConfigurationForm(array &$form, array &$form_state) { } /** * {@inheritdoc} */ - public function submitEditForm(array &$form, array &$form_state) { + public function submitConfigurationForm(array &$form, array &$form_state) { $new_definition = $this->extractFormValues($form, $form_state); return $this->menuTree->updateLink($this->menuLink->getPluginId(), $new_definition); @@ -180,8 +180,9 @@ public function submitEditForm(array &$form, array &$form_state) { /** * Helper function to get a module name. * - * @todo - this function is horrible, but core has nothing better. Add a - * a method to the ModuleHandler that handles this nicely. + * This function is horrible, but core has nothing better until we add a + * a method to the ModuleHandler that handles this nicely. + * @see https://drupal.org/node/2281989 */ protected function getModuleName($module) { // Gather module data. @@ -195,4 +196,5 @@ protected function getModuleName($module) { // Otherwise, return the machine name. return $module; } + } diff --git a/core/lib/Drupal/Core/Menu/Form/MenuLinkFormInterface.php b/core/lib/Drupal/Core/Menu/Form/MenuLinkFormInterface.php index f92c761..e9f9522 100644 --- a/core/lib/Drupal/Core/Menu/Form/MenuLinkFormInterface.php +++ b/core/lib/Drupal/Core/Menu/Form/MenuLinkFormInterface.php @@ -7,15 +7,16 @@ namespace Drupal\Core\Menu\Form; +use Drupal\Core\Plugin\PluginFormInterface; use Drupal\Core\Menu\MenuLinkInterface; /** * Defines an interface for edit forms on menu links. * - * Depending on the menu link plugin there should be more or less things - * to change. + * All menu link plugins use the same interface for their configuration or + * editing form, but */ -interface MenuLinkFormInterface { +interface MenuLinkFormInterface extends PluginFormInterface { /** * Injects the menu link plugin. @@ -26,42 +27,6 @@ public function setMenuLinkInstance(MenuLinkInterface $menu_link); /** - * Form constructor. - * - * @param array $form - * An associative array containing the structure of the form. - * @param array $form_state - * An associative array containing the current state of the form. - * - * @return array - * The form structure. - */ - public function buildEditForm(array &$form, array &$form_state); - - /** - * Form validation handler. - * - * @param array $form - * An associative array containing the structure of the form. - * @param array $form_state - * An associative array containing the current state of the form. - */ - public function validateEditForm(array &$form, array &$form_state); - - /** - * Form submission handler. - * - * @param array $form - * An associative array containing the structure of the form. - * @param array $form_state - * An associative array containing the current state of the form. - * - * @return \Drupal\Core\Menu\MenuLinkInterface - * The updated instance. - */ - public function submitEditForm(array &$form, array &$form_state); - - /** * Form plugin helper. * * @param array $form diff --git a/core/lib/Drupal/Core/Menu/MenuLinkDefault.php b/core/lib/Drupal/Core/Menu/MenuLinkDefault.php index 170ea19..be35f12 100644 --- a/core/lib/Drupal/Core/Menu/MenuLinkDefault.php +++ b/core/lib/Drupal/Core/Menu/MenuLinkDefault.php @@ -86,11 +86,4 @@ public function updateLink(array $new_definition_values, $persist) { return $this->pluginDefinition; } - /** - * {@inheritdoc} - */ - public function persistLinkDeletion() { - // @todo - what should this do by default? - } - } diff --git a/core/lib/Drupal/Core/Menu/MenuLinkTree.php b/core/lib/Drupal/Core/Menu/MenuLinkTree.php index 32eb757..07e1cd4 100644 --- a/core/lib/Drupal/Core/Menu/MenuLinkTree.php +++ b/core/lib/Drupal/Core/Menu/MenuLinkTree.php @@ -303,7 +303,7 @@ public function getDefinitions() { } else { // Any link found here is flagged as discovered, so it can be purged - // if it does exit in the future. + // if it does not exist in the future. $definitions[$plugin_id]['discovered'] = 1; } } diff --git a/core/lib/Drupal/Core/Menu/MenuLinkTreeInterface.php b/core/lib/Drupal/Core/Menu/MenuLinkTreeInterface.php index a75e284..c4f6b6a 100644 --- a/core/lib/Drupal/Core/Menu/MenuLinkTreeInterface.php +++ b/core/lib/Drupal/Core/Menu/MenuLinkTreeInterface.php @@ -10,7 +10,7 @@ use Drupal\Component\Plugin\PluginManagerInterface; /** - * Provides an object which returns the available menu links. + * Defines an interface for creating menu links and retrieving menu link trees. */ interface MenuLinkTreeInterface extends PluginManagerInterface { @@ -394,4 +394,5 @@ public function getParentDepthLimit($id); * Resets any local definition cache. Used for testing. */ public function resetDefinitions(); + } diff --git a/core/lib/Drupal/Core/Menu/MenuTreeStorage.php b/core/lib/Drupal/Core/Menu/MenuTreeStorage.php index 3931a3a..22c3373 100644 --- a/core/lib/Drupal/Core/Menu/MenuTreeStorage.php +++ b/core/lib/Drupal/Core/Menu/MenuTreeStorage.php @@ -234,7 +234,6 @@ 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?. - $affected_menus = array(); $transaction = $this->connection->startTransaction(); @@ -518,12 +517,10 @@ protected function findParent($link, $original) { $candidates[] = $link['parent']; } elseif (!empty($original['parent']) && $link['menu_name'] == $original['menu_name']) { + // Otherwise, fall back to the original parent. $candidates[] = $original['parent']; } - // Else, if we have a link hierarchy try to find a valid parent in there. - // @todo - why does this make sense to do at all? - foreach ($candidates as $id) { $parent = $this->loadFull($id); if ($parent) { @@ -1221,10 +1218,28 @@ protected static function schemaDefinition() { ), ), 'indexes' => array( - 'menu_parents' => array('menu_name', 'p1', 'p2', 'p3', 'p4', 'p5', 'p6', 'p7', 'p8', 'p9'), + 'menu_parents' => array( + 'menu_name', + 'p1', + 'p2', + 'p3', + 'p4', + 'p5', + 'p6', + 'p7', + 'p8', + 'p9', + ), // @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)), + '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), + ), ), 'primary key' => array('mlid'), 'unique keys' => array( diff --git a/core/lib/Drupal/Core/Menu/MenuTreeStorageInterface.php b/core/lib/Drupal/Core/Menu/MenuTreeStorageInterface.php index d90a767..273312f 100644 --- a/core/lib/Drupal/Core/Menu/MenuTreeStorageInterface.php +++ b/core/lib/Drupal/Core/Menu/MenuTreeStorageInterface.php @@ -250,4 +250,5 @@ public function getMenuNames(); * The amount of menu links. */ public function countMenuLinks($menu_name = NULL); + } diff --git a/core/modules/menu_link_content/menu_link_content.info.yml b/core/modules/menu_link_content/menu_link_content.info.yml index 4c69873..a82c890 100644 --- a/core/modules/menu_link_content/menu_link_content.info.yml +++ b/core/modules/menu_link_content/menu_link_content.info.yml @@ -1,4 +1,4 @@ -name: 'Menu Links Content' +name: 'Menu Link Content' type: module description: 'Allows administrators to create custom links' package: Core diff --git a/core/modules/menu_link_content/src/Entity/MenuLinkContent.php b/core/modules/menu_link_content/src/Entity/MenuLinkContent.php index d41afea..cecfe13 100644 --- a/core/modules/menu_link_content/src/Entity/MenuLinkContent.php +++ b/core/modules/menu_link_content/src/Entity/MenuLinkContent.php @@ -335,6 +335,10 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setDescription(t('A flag to indicate if the link points to a full URL starting with a protocol, like http:// (1 = external, 0 = internal).')) ->setSetting('default_value', 0); + // The form widget doesn't work yet for core fields, so we skip the + // for display and manually create form elements for the boolean fields. + // @see https://drupal.org/node/2226493 + // @see https://drupal.org/node/2150511 $fields['expanded'] = FieldDefinition::create('boolean') ->setLabel(t('Expanded')) ->setDescription(t('Flag for whether this link should be rendered as expanded in menus - expanded links always have their child links displayed, instead of only when the link is in the active trail (1 = expanded, 0 = not expanded).')) @@ -343,13 +347,9 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { 'label' => 'hidden', 'type' => 'boolean', 'weight' => 0, - )) - ->setDisplayOptions('form', array( - 'type' => 'options_onoff', - 'weight' => 0, )); - // We manual create a form element for this, since the form logic is + // We manually create a form element for this, since the form logic is // is inverted to show enabled. $fields['hidden'] = FieldDefinition::create('boolean') ->setLabel(t('Hidden')) diff --git a/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php b/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php index 272ac64..5dc37fe 100644 --- a/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php +++ b/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php @@ -27,8 +27,8 @@ * Provides a form to add/update content menu links. * * Note: This is not only a content entity form, but also implements the - * MenuLinkFormInterface, which works as a generic menu link edit form, so for - * example static menu links as well. + * MenuLinkFormInterface, so the same class can be used in places expecting a + * generic menu link plugin configuration form. */ class MenuLinkContentForm extends ContentEntityForm implements MenuLinkFormInterface { @@ -118,12 +118,25 @@ public function setMenuLinkInstance(MenuLinkInterface $menu_link) { /** * {@inheritdoc} */ + public function buildConfigurationForm(array $form, array &$form_state) { + return $this->buildEditForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ public function buildEditForm(array &$form, array &$form_state) { $this->setOperation('default'); $this->init($form_state); return $this->form($form, $form_state); } + /** + * {@inheritdoc} + */ + public function validateConfigurationForm(array &$form, array &$form_state) { + $this->doValidate($form, $form_state); + } /** * {@inheritdoc} @@ -135,6 +148,13 @@ public function validateEditForm(array &$form, array &$form_state) { /** * {@inheritdoc} */ + public function submitConfigurationForm(array &$form, array &$form_state) { + return $this->submitEditForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ public function submitEditForm(array &$form, array &$form_state) { // Remove button and internal Form API values from submitted values. form_state_values_clean($form_state); diff --git a/core/modules/menu_ui/src/Form/MenuLinkEditForm.php b/core/modules/menu_ui/src/Form/MenuLinkEditForm.php index 16f6ab5..4f5ef2b 100644 --- a/core/modules/menu_ui/src/Form/MenuLinkEditForm.php +++ b/core/modules/menu_ui/src/Form/MenuLinkEditForm.php @@ -65,7 +65,7 @@ public function buildForm(array $form, array &$form_state, MenuLinkInterface $me $form['#plugin_form'] = $this->menuTree->getPluginForm($menu_link_plugin); - $form += $form['#plugin_form']->buildEditForm($form, $form_state); + $form += $form['#plugin_form']->buildConfigurationForm($form, $form_state); $form['actions'] = array('#type' => 'actions'); $form['actions']['submit'] = array( diff --git a/core/modules/views/src/Plugin/Menu/Form/ViewsMenuLinkForm.php b/core/modules/views/src/Plugin/Menu/Form/ViewsMenuLinkForm.php index ac5d566..a6313b2 100644 --- a/core/modules/views/src/Plugin/Menu/Form/ViewsMenuLinkForm.php +++ b/core/modules/views/src/Plugin/Menu/Form/ViewsMenuLinkForm.php @@ -15,7 +15,7 @@ class ViewsMenuLinkForm extends MenuLinkDefaultForm { /** * {@inheritdoc} */ - public function buildEditForm(array &$form, array &$form_state) { + public function buildConfigurationForm(array $form, array &$form_state) { // Put the title field first. $form['title'] = array( @@ -24,7 +24,7 @@ public function buildEditForm(array &$form, array &$form_state) { '#default_value' => $this->menuLink->getTitle(), ); - $form += parent::buildEditForm($form, $form_state); + $form += parent::buildConfigurationForm($form, $form_state); if ($this->menuLink instanceof ViewsMenuLink) { $view = $this->menuLink->loadView();