public MenuForm::form(array $form, FormStateInterface $form_state)
Gets the actual form array to be built.
Overrides EntityForm::form
See also
\Drupal\Core\Entity\EntityForm::processForm()
\Drupal\Core\Entity\EntityForm::afterBuild()
File
- core/modules/menu_ui/src/MenuForm.php, line 95
Class
- MenuForm
- Base form for menu edit forms.
Namespace
Drupal\menu_ui
Code
public function form(array $form, FormStateInterface $form_state) {
$menu = $this->entity;
if ($this->operation == 'edit') {
$form['#title'] = $this->t('Edit menu %label', array('%label' => $menu->label()));
}
$form['label'] = array(
'#type' => 'textfield',
'#title' => $this->t('Title'),
'#default_value' => $menu->label(),
'#required' => TRUE,
);
$form['id'] = array(
'#type' => 'machine_name',
'#title' => $this->t('Menu name'),
'#default_value' => $menu->id(),
'#maxlength' => MENU_MAX_MENU_NAME_LENGTH_UI,
'#description' => $this->t('A unique name to construct the URL for the menu. It must only contain lowercase letters, numbers and hyphens.'),
'#machine_name' => array(
'exists' => array($this, 'menuNameExists'),
'source' => array('label'),
'replace_pattern' => '[^a-z0-9-]+',
'replace' => '-',
),
// A menu's machine name cannot be changed.
'#disabled' => !$menu->isNew() || $menu->isLocked(),
);
$form['description'] = array(
'#type' => 'textfield',
'#title' => t('Administrative summary'),
'#maxlength' => 512,
'#default_value' => $menu->getDescription(),
);
$form['langcode'] = array(
'#type' => 'language_select',
'#title' => t('Menu language'),
'#languages' => LanguageInterface::STATE_ALL,
'#default_value' => $menu->language()->getId(),
);
// Add menu links administration form for existing menus.
if (!$menu->isNew() || $menu->isLocked()) {
// Form API supports constructing and validating self-contained sections
// within forms, but does not allow handling the form section's submission
// equally separated yet. Therefore, we use a $form_state key to point to
// the parents of the form section.
// @see self::submitOverviewForm()
$form_state->set('menu_overview_form_parents', ['links']);
$form['links'] = array();
$form['links'] = $this->buildOverviewForm($form['links'], $form_state);
}
return parent::form($form, $form_state);
}
Please login to continue.