SystemMenuOffCanvasForm::buildConfigurationForm

public SystemMenuOffCanvasForm::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.

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/outside_in/src/Form/SystemMenuOffCanvasForm.php, line 77

Class

SystemMenuOffCanvasForm
The off-canvas form handler for the SystemMenuBlock.

Namespace

Drupal\outside_in\Form

Code

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', array('%label' => $this->entity->label())),
    '#open' => TRUE,
  ];
  $form['entity_form'] += $this->getEntityForm($this->entity)->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;
}
doc_Drupal
2016-10-29 09:45:50
Comments
Leave a Comment

Please login to continue.