public function OverviewForm::buildForm in Queue UI 8.2
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/ OverviewForm.php, line 131
Class
- OverviewForm
- Class QueueUIOverviewForm @package Drupal\queue_ui\Form
Namespace
Drupal\queue_ui\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$form['top'] = [
'operation' => [
'#type' => 'select',
'#title' => $this
->t('Action'),
'#options' => [
'submitBatch' => $this
->t('Batch process'),
'submitRelease' => $this
->t('Remove leases'),
'submitClear' => $this
->t('Clear'),
],
],
'actions' => [
'#type' => 'container',
'#attributes' => [
'class' => [
'form-actions',
],
],
'apply' => [
'#type' => 'submit',
'#tableselect' => TRUE,
'#submit' => [
'::submitBulkForm',
],
'#value' => $this
->t('Apply to selected items'),
],
],
];
$form['queues'] = [
'#type' => 'table',
'#tableselect' => TRUE,
'#header' => [
'title' => $this
->t('Title'),
'items' => $this
->t('Number of items'),
'class' => $this
->t('Class'),
'cron' => $this
->t('Cron time limit (seconds)'),
'operations' => $this
->t('Operations'),
],
'#empty' => $this
->t('No queues defined'),
];
$queue_order_installed = $this->moduleHandler
->moduleExists('queue_order');
if ($queue_order_installed) {
// Add the dragable options for the form.
$form['queues']['#tabledrag'] = [
[
'action' => 'order',
'relationship' => 'sibling',
'group' => 'queue-order-weight',
],
];
// Add the weight to the table header.
$form['queues']['#header']['weight'] = $this
->t('Weight');
$form['weight'] = [
'#type' => 'value',
];
}
// Get queues names.
$queues = $this->queueWorkerManager
->getDefinitions();
foreach ($queues as $name => $queue_definition) {
$queue = $this->queueFactory
->get($name);
$operations = [];
// If queue inspection is enabled for this implementation.
if ($queue_ui = $this->queueUIManager
->fromQueueName($name)) {
$operations['inspect'] = [
'title' => $this
->t('Inspect'),
'url' => Url::fromRoute('queue_ui.inspect', [
'queue_name' => $name,
]),
];
}
$row = [
'title' => [
'#markup' => (string) $queue_definition['title'],
],
'items' => [
'#markup' => $queue
->numberOfItems(),
],
'class' => [
'#markup' => $this->queueUIManager
->queueClassName($queue),
],
'cron' => [
'#type' => 'number',
'#title' => $this
->t('Cron Time'),
'#title_display' => 'hidden',
'#placeholder' => $this
->t('Cron disabled'),
'#value' => isset($queue_definition['cron']['time']) ? $queue_definition['cron']['time'] : '',
'#parents' => [],
'#name' => 'cron[' . $name . ']',
],
'operations' => [
'#type' => 'dropbutton',
'#links' => $operations,
],
];
// Enable sort if queue_order is enabled.
if ($queue_order_installed) {
$weight = isset($queue_definition['weight']) ? $queue_definition['weight'] : 10;
$row['#attributes'] = [
'class' => [
'draggable',
],
];
$row['#weight'] = $weight;
$row['weight'] = [
'#type' => 'weight',
'#title' => $this
->t('Weight for @title', [
'@title' => $name,
]),
'#title_display' => 'invisible',
'#default_value' => $weight,
'#name' => 'weight[' . $name . ']',
// Classify the weight element for #tabledrag.
'#attributes' => [
'class' => [
'queue-order-weight',
],
],
];
}
$form['queues'][$name] = $row;
}
$form['cron'] = [
'#type' => 'value',
];
$form['botton'] = [
'actions' => [
'#type' => 'container',
'#attributes' => [
'class' => [
'form-actions',
],
],
'apply' => [
'#type' => 'submit',
'#tableselect' => TRUE,
'#submit' => [
'::submitBulkForm',
],
'#value' => $this
->t('Apply to selected items'),
],
'save' => [
'#type' => 'submit',
'#value' => $this
->t('Save changes'),
],
],
];
return $form;
}