function MenuLinkEditForm::buildForm

Same name and namespace in other branches
  1. 9 core/modules/menu_ui/src/Form/MenuLinkEditForm.php \Drupal\menu_ui\Form\MenuLinkEditForm::buildForm()
  2. 8.9.x core/modules/menu_ui/src/Form/MenuLinkEditForm.php \Drupal\menu_ui\Form\MenuLinkEditForm::buildForm()
  3. 11.x core/modules/menu_ui/src/Form/MenuLinkEditForm.php \Drupal\menu_ui\Form\MenuLinkEditForm::buildForm()

Form constructor.

Parameters

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

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

\Drupal\Core\Menu\MenuLinkInterface $menu_link_plugin: The plugin instance to use for this form.

Return value

array The form structure.

Overrides FormInterface::buildForm

File

core/modules/menu_ui/src/Form/MenuLinkEditForm.php, line 65

Class

MenuLinkEditForm
Defines a generic edit form for all menu link plugin types.

Namespace

Drupal\menu_ui\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, ?MenuLinkInterface $menu_link_plugin = NULL) {
  $form['menu_link_id'] = [
    '#type' => 'value',
    '#value' => $menu_link_plugin->getPluginId(),
  ];
  $class_name = $menu_link_plugin->getFormClass();
  $form['#plugin_form'] = $this->classResolver
    ->getInstanceFromDefinition($class_name);
  $form['#plugin_form']->setMenuLinkInstance($menu_link_plugin);
  $form += $form['#plugin_form']->buildConfigurationForm($form, $form_state);
  $form['actions'] = [
    '#type' => 'actions',
  ];
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this->t('Save'),
    '#button_type' => 'primary',
  ];
  return $form;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.