public function SystemMenuOffCanvasForm::buildConfigurationForm in Drupal 8
Same name and namespace in other branches
- 9 core/modules/system/src/Form/SystemMenuOffCanvasForm.php \Drupal\system\Form\SystemMenuOffCanvasForm::buildConfigurationForm()
- 10 core/modules/system/src/Form/SystemMenuOffCanvasForm.php \Drupal\system\Form\SystemMenuOffCanvasForm::buildConfigurationForm()
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.
Parameters
array $form: An associative array containing the initial structure of the plugin form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().
Return value
array The form structure.
Overrides PluginFormInterface::buildConfigurationForm
File
- core/
modules/ system/ src/ Form/ SystemMenuOffCanvasForm.php, line 91
Class
- SystemMenuOffCanvasForm
- The setting_tray form handler for the SystemMenuBlock.
Namespace
Drupal\system\FormCode
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = $this->plugin
->buildConfigurationForm([], $form_state);
// Move the menu levels section to the bottom.
$form['menu_levels']['#weight'] = 100;
$form['entity_form'] = [
'#type' => 'details',
'#title' => $this
->t('Edit menu %label', [
'%label' => $this->menu
->label(),
]),
'#open' => TRUE,
'#access' => !$this
->hasMenuOverrides() && $this->menu
->access('edit'),
];
$form['entity_form'] += $this
->getEntityForm($this->menu)
->buildForm([], $form_state);
// Print the menu link titles as text instead of a link.
if (!empty($form['entity_form']['links']['links'])) {
foreach (Element::children($form['entity_form']['links']['links']) as $child) {
$title = $form['entity_form']['links']['links'][$child]['title'][1]['#title'];
$form['entity_form']['links']['links'][$child]['title'][1] = [
'#markup' => $title,
];
}
}
// Change the header text.
$form['entity_form']['links']['links']['#header'][0] = $this
->t('Link');
$form['entity_form']['links']['links']['#header'][1]['data'] = $this
->t('On');
// Remove the label, ID, description, and buttons from the entity form.
unset($form['entity_form']['label'], $form['entity_form']['id'], $form['entity_form']['description'], $form['entity_form']['actions']);
// Since the overview form is further nested than expected, update the
// #parents. See \Drupal\menu_ui\MenuForm::form().
$form_state
->set('menu_overview_form_parents', [
'settings',
'entity_form',
'links',
]);
return $form;
}