You are here

public function EnqueueForm::buildForm in Warmer 8

Same name and namespace in other branches
  1. 2.x src/Form/EnqueueForm.php \Drupal\warmer\Form\EnqueueForm::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/EnqueueForm.php, line 95

Class

EnqueueForm
A form to manually enqueue warming operations.

Namespace

Drupal\warmer\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form['help'] = [
    '#type' => 'item',
    '#description' => $this
      ->t('This page allows you to enqueue cache warming operations manually. This will put the cache warming operations in a queue. If you want to actually execute them right away you can force processing the queue. A good way to do that is by installing the <a href=":url">Queue UI</a> module or using Drush. This module will provide a UI to process an entire queue.', [
      ':url' => 'https://www.drupal.org/project/queue_ui',
    ]),
  ];
  $options = array_map(function (array $definition) {
    return [
      'title' => $definition['label'],
      'description' => $definition['description'],
    ];
  }, $this->warmerManager
    ->getDefinitions());
  $header = [
    'title' => $this
      ->t('Warmer'),
    'description' => $this
      ->t('Description'),
  ];
  $form['warmers'] = [
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $options,
    '#empty' => $this
      ->t('No warmers available. Enable the Entity Warmer submodule, or try installing extending modules like JSON:API Boost.'),
  ];
  $form['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Warm Caches'),
    '#button_type' => 'primary',
  ];
  try {

    // If Queue UI exists, link to it.
    $this->routeProvider
      ->getRouteByName('queue_ui.overview_form');
    $form['queues'] = [
      '#type' => 'link',
      '#title' => $this
        ->t('List of queues'),
      '#url' => Url::fromRoute('queue_ui.overview_form'),
    ];
  } catch (RouteNotFoundException $e) {
  }
  return $form;
}