/Drupal 8

public function MenuLinkDefaultForm::buildConfigurationForm

public MenuLinkDefaultForm::buildConfigurationForm(array $form, FormStateInterface $form_state)

Form constructor.

Plugin forms are embedded in other forms. In order to know where the plugin form is located in the parent form, #parents and #array_parents must be known, but these are not available during the initial build phase. In order to have these properties available when building the plugin form's elements, let this method return a form element that has a #process callback and build the rest of the form in the callback. By the time the callback is executed, the element's #parents and #array_parents properties will have been set by the form API. For more documentation on #parents and #array_parents, see \Drupal\Core\Render\Element\FormElement.


array $form: An associative array containing the initial structure of the plugin form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the complete form.

Return value

array The form structure.

Overrides PluginFormInterface::buildConfigurationForm


core/lib/Drupal/Core/Menu/Form/MenuLinkDefaultForm.php, line 100


Provides an edit form for static menu links.




public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  $form['#title'] = $this->t('Edit menu link %title', array('%title' => $this->menuLink->getTitle()));

  $provider = $this->menuLink->getProvider();
  $form['info'] = array(
    '#type' => 'item',
    '#title' => $this->t('This link is provided by the @name module. The title and path cannot be edited.', array('@name' => $this->moduleHandler->getName($provider))),
  $form['id'] = array(
    '#type' => 'value',
    '#value' => $this->menuLink->getPluginId(),
  $link = array(
    '#type' => 'link',
    '#title' => $this->menuLink->getTitle(),
    '#url' => $this->menuLink->getUrlObject(),
  $form['path'] = array(
    'link' => $link,
    '#type' => 'item',
    '#title' => $this->t('Link'),

  $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->menuLink->isEnabled(),

  $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.'),
    '#default_value' => $this->menuLink->isExpanded(),

  $menu_parent = $this->menuLink->getMenuName() . ':' . $this->menuLink->getParent();
  $form['menu_parent'] = $this->menuParentSelector->parentSelectElement($menu_parent, $this->menuLink->getPluginId());
  $form['menu_parent']['#title'] = $this->t('Parent link');
  $form['menu_parent']['#description'] = $this->t('The maximum depth for a link and all its children is fixed. Some menu links may not be available as parents if selecting them would exceed this limit.');
  $form['menu_parent']['#attributes']['class'][] = 'menu-title-select';

  $delta = max(abs($this->menuLink->getWeight()), 50);
  $form['weight'] = array(
    '#type' => 'number',
    '#min' => -$delta,
    '#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. In the menu, the links with high weight will sink and links with a low weight will be positioned nearer the top.'),

  return $form;

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.