You are here

public function PageVariantConfigureForm::buildForm in Page Manager 8

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

page_manager_ui/src/Form/PageVariantConfigureForm.php, line 28
Contains \Drupal\page_manager_ui\Form\PageVariantConfigureForm.

Class

PageVariantConfigureForm

Namespace

Drupal\page_manager_ui\Form

Code

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

  /** @var \Drupal\page_manager\PageInterface $page */
  $page = $cached_values['page'];

  /** @var \Drupal\page_manager\PageVariantInterface $page_variant */
  $page_variant = $cached_values['page_variant'];
  $form['page_variant_label'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Label'),
    '#required' => TRUE,
    '#size' => 32,
    '#maxlength' => 255,
    '#default_value' => $page_variant
      ->label(),
  ];
  $variant_plugin = $page_variant
    ->getVariantPlugin();
  $form['variant_settings'] = $variant_plugin
    ->buildConfigurationForm([], (new FormState())
    ->setValues($form_state
    ->getValue('variant_settings', [])));
  $form['variant_settings']['#tree'] = TRUE;
  if (!$page
    ->isNew()) {
    $form['delete'] = [
      '#type' => 'link',
      '#title' => $this
        ->t('Delete this variant'),
      '#attributes' => [
        'class' => [
          'button',
          'use-ajax',
        ],
        'data-dialog-type' => 'modal',
      ],
      '#url' => new Url('entity.page_variant.delete_form', [
        'machine_name' => $page
          ->id(),
        'variant_machine_name' => $page_variant
          ->id(),
      ]),
    ];
  }
  return $form;
}