You are here

public function ParameterEditForm::buildForm in Page Manager 8

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

Class

ParameterEditForm
Provides a form for editing a parameter.

Namespace

Drupal\page_manager_ui\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $name = '', $tempstore_id = NULL, $machine_name = NULL) {
  $this->tempstore_id = $tempstore_id;
  $this->machine_name = $machine_name;
  $cached_values = $this
    ->getTempstore();
  $page = $cached_values['page'];
  $parameter = $page
    ->getParameter($name);
  $form['machine_name'] = [
    '#type' => 'value',
    '#value' => $name,
  ];
  $form['label'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Label'),
    '#default_value' => $parameter['label'] ?: ucfirst($parameter['machine_name']),
    '#states' => [
      'invisible' => [
        ':input[name="type"]' => [
          'value' => static::NO_CONTEXT_KEY,
        ],
      ],
    ],
  ];
  $form['type'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Type'),
    '#required' => TRUE,
    '#options' => $this
      ->buildParameterTypeOptions(),
    '#default_value' => $parameter['type'],
  ];
  $form['actions'] = [
    '#type' => 'actions',
  ];
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Update parameter'),
    '#button_type' => 'primary',
  ];
  return $form;
}