You are here

public function PurgeBlockForm::buildForm in Purge 8.3

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

modules/purge_ui/src/Form/PurgeBlockForm.php, line 164

Class

PurgeBlockForm
End-user form for \Drupal\purge_ui\Plugin\Block\PurgeBlock.

Namespace

Drupal\purge_ui\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form_state
    ->addBuildInfo('expressions', $this
    ->gatherInvalidationsData());
  $form = [];
  if ($this->config['execution'] === 'direct' && !$this->processor) {
    $this->messenger
      ->addError($this
      ->t('Please contact your site administrator to enable the block processor plugin.'));
    return [
      'messages' => [
        '#type' => 'status_messages',
      ],
    ];
  }
  if ($this->config['execution'] === 'queue' && !$this->queuer) {
    $this->messenger
      ->addError($this
      ->t('Please contact your site administrator to enable the block queuer plugin.'));
    return [
      'messages' => [
        '#type' => 'status_messages',
      ],
    ];
  }
  if (!empty($this->config['description'])) {
    $form['description'] = [
      '#type' => 'html_tag',
      '#tag' => 'p',
      '#value' => $this->config['description'],
    ];
  }
  $form['submit'] = [
    '#type' => 'submit',
    '#value' => $this->config['submit_label'],
  ];
  return $form;
}