You are here

public function ConfigureSectionForm::buildForm in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/layout_builder/src/Form/ConfigureSectionForm.php \Drupal\layout_builder\Form\ConfigureSectionForm::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.

Return value

array The form structure.

Overrides FormInterface::buildForm

File

core/modules/layout_builder/src/Form/ConfigureSectionForm.php, line 107

Class

ConfigureSectionForm
Provides a form for configuring a layout section.

Namespace

Drupal\layout_builder\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, SectionStorageInterface $section_storage = NULL, $delta = NULL, $plugin_id = NULL) {
  $this->sectionStorage = $section_storage;
  $this->delta = $delta;
  $this->isUpdate = is_null($plugin_id);
  if ($this->isUpdate) {
    $section = $this->sectionStorage
      ->getSection($this->delta);
    if ($label = $section
      ->getLayoutSettings()['label']) {
      $form['#title'] = $this
        ->t('Configure @section', [
        '@section' => $label,
      ]);
    }
  }
  else {
    $section = new Section($plugin_id);
  }
  $this->layout = $section
    ->getLayout();
  $form['#tree'] = TRUE;
  $form['layout_settings'] = [];
  $subform_state = SubformState::createForSubform($form['layout_settings'], $form, $form_state);
  $form['layout_settings'] = $this
    ->getPluginForm($this->layout)
    ->buildConfigurationForm($form['layout_settings'], $subform_state);
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this->isUpdate ? $this
      ->t('Update') : $this
      ->t('Add section'),
    '#button_type' => 'primary',
  ];
  if ($this
    ->isAjax()) {
    $form['actions']['submit']['#ajax']['callback'] = '::ajaxSubmit';
  }
  $target_highlight_id = $this->isUpdate ? $this
    ->sectionUpdateHighlightId($delta) : $this
    ->sectionAddHighlightId($delta);
  $form['#attributes']['data-layout-builder-target-highlight-id'] = $target_highlight_id;

  // Mark this as an administrative page for JavaScript ("Back to site" link).
  $form['#attached']['drupalSettings']['path']['currentPathIsAdmin'] = TRUE;
  return $form;
}