You are here

public function LayoutPluginSelector::buildForm in Panels 8.3

Same name and namespace in other branches
  1. 8.4 src/Form/LayoutPluginSelector.php \Drupal\panels\Form\LayoutPluginSelector::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

src/Form/LayoutPluginSelector.php, line 64

Class

LayoutPluginSelector
Provides a form for selecting a layout plugin.

Namespace

Drupal\panels\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $cached_values = $form_state
    ->getTemporaryValue('wizard');

  /* @var $variant_plugin \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant */
  $variant_plugin = $cached_values['plugin'];
  $form['layout'] = [
    '#title' => $this
      ->t('Layout'),
    '#type' => 'select',
    '#options' => Layout::layoutPluginManager()
      ->getLayoutOptions([
      'group_by_category' => TRUE,
    ]),
    '#default_value' => $variant_plugin
      ->getConfiguration()['layout'] ?: NULL,
  ];
  $wizard = $form_state
    ->getFormObject();
  $form['update_layout'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Change Layout'),
    '#access' => !empty($variant_plugin
      ->getConfiguration()['layout']),
    '#validate' => [
      [
        $this,
        'validateForm',
      ],
    ],
    '#submit' => [
      [
        $this,
        'submitForm',
      ],
      [
        $wizard,
        'submitForm',
      ],
    ],
  ];
  return $form;
}