class OverviewForm in Queue UI 8.2
Class QueueUIOverviewForm @package Drupal\queue_ui\Form
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\queue_ui\Form\OverviewForm
Expanded class hierarchy of OverviewForm
1 string reference to 'OverviewForm'
File
- src/
Form/ OverviewForm.php, line 25
Namespace
Drupal\queue_ui\FormView source
class OverviewForm extends FormBase {
/**
* The queue factory.
*
* @var \Drupal\Core\Queue\QueueFactory
*/
protected $queueFactory;
/**
* The tempstore factory.
*
* @var \Drupal\Core\TempStore\PrivateTempStoreFactory
*/
protected $tempStoreFactory;
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $currentUser;
/**
* The Drupal state storage.
*
* @var \Drupal\Core\State\StateInterface
*/
protected $state;
/**
* The Drupal module handler.
*
* @var \Drupal\Core\Extension\ModuleHandler
*/
protected $moduleHandler;
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $dbConnection;
/**
* @var \Drupal\Core\Queue\QueueWorkerManager
*/
private $queueWorkerManager;
/**
* @var \Drupal\queue_ui\QueueUIManager
*/
private $queueUIManager;
/**
* OverviewForm constructor.
*
* @param \Drupal\Core\Queue\QueueFactory $queue_factory
* @param \Drupal\Core\TempStore\PrivateTempStoreFactory $temp_store_factory
* @param \Drupal\Core\Session\AccountInterface $current_user
* @param \Drupal\Core\State\StateInterface $state
* @param \Drupal\Core\Extension\ModuleHandler $module_handler
* @param \Drupal\Core\Queue\QueueWorkerManager $queueWorkerManager
* @param \Drupal\queue_ui\QueueUIManager $queueUIManager
* @param \Drupal\Core\Messenger\Messenger $messenger
*/
public function __construct(QueueFactory $queue_factory, PrivateTempStoreFactory $temp_store_factory, AccountInterface $current_user, StateInterface $state, ModuleHandler $module_handler, QueueWorkerManager $queueWorkerManager, QueueUIManager $queueUIManager, Messenger $messenger) {
$this->queueFactory = $queue_factory;
$this->tempStoreFactory = $temp_store_factory;
$this->currentUser = $current_user;
$this->state = $state;
$this->moduleHandler = $module_handler;
$this->dbConnection = Database::getConnection('default');
$this->queueWorkerManager = $queueWorkerManager;
$this->queueUIManager = $queueUIManager;
$this->messenger = $messenger;
}
/**
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
* @return static
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('queue'), $container
->get('tempstore.private'), $container
->get('current_user'), $container
->get('state'), $container
->get('module_handler'), $container
->get('plugin.manager.queue_worker'), $container
->get('plugin.manager.queue_ui'), $container
->get('messenger'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'queue_ui_overview_form';
}
/**
* {@inheritdoc}
*/
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;
}
/**
* We need this method, but each button has its own submit handler.
*
* @param array $form
* @param \Drupal\Core\Form\FormStateInterface $form_state
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$form_state
->cleanValues();
foreach ($form_state
->getValue('cron') as $name => $time) {
$this->state
->set('queue_ui_cron_' . $name, $time);
}
// Only save the weight if the queue_order module is available.
if ($this->moduleHandler
->moduleExists('queue_order')) {
$order_config = $this
->configFactory()
->getEditable('queue_order.settings');
// Save the weight of the defined workers.
foreach ($form_state
->getValue('weight') as $name => $weight) {
$order_config
->set('order.' . $name, (int) $weight);
}
$order_config
->save();
}
// Clear the cached plugin definition so that changes come into effect.
$this->queueWorkerManager
->clearCachedDefinitions();
}
/**
* @param array $form
* @param \Drupal\Core\Form\FormStateInterface $form_state
*/
public function submitBulkForm(array &$form, FormStateInterface $form_state) {
if (in_array($form_state
->getValue('operation'), [
'submitBatch',
'submitRelease',
'submitClear',
])) {
$selected_queues = array_filter($form_state
->getValue('queues'));
if (!empty($selected_queues)) {
$this
->{$form_state
->getValue('operation')}($form_state, $selected_queues);
}
}
}
/**
* Process queue(s) with batch.
*
* @param \Drupal\Core\Form\FormStateInterface $form_state
* @param $queues
*/
public function submitBatch(FormStateInterface $form_state, $queues) {
$batch = [
'title' => $this
->t('Processing queues'),
'operations' => [],
'finished' => [
'\\Drupal\\queue_ui\\QueueUIBatch',
'finish',
],
];
foreach ($queues as $queue_name) {
$batch['operations'][] = [
'\\Drupal\\queue_ui\\QueueUIBatch::step',
[
$queue_name,
],
];
}
batch_set($batch);
}
/**
* Option to remove lease timestamps.
*
* @param \Drupal\Core\Form\FormStateInterface $form_state
* @param $queues
*/
public function submitRelease(FormStateInterface $form_state, $queues) {
foreach ($queues as $queue_name) {
/** @var QueueUIInterface $queue_ui */
if ($queue_ui = $this->queueUIManager
->fromQueueName($queue_name)) {
$num_updated = $queue_ui
->releaseItems($queue_name);
$this->messenger
->addMessage($this
->t('@count lease reset in queue @name', [
'@count' => $num_updated,
'@name' => $queue_name,
]));
}
}
}
/**
* Option to delete queue.
*
* @param \Drupal\Core\Form\FormStateInterface $form_state
* @param $queues
*/
public function submitClear(FormStateInterface $form_state, $queues) {
$this->tempStoreFactory
->get('queue_ui_clear_queues')
->set($this->currentUser
->id(), $queues);
$form_state
->setRedirect('queue_ui.confirm_clear_form');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Retrieves a configuration object. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
62 |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
OverviewForm:: |
protected | property | The current user. | |
OverviewForm:: |
protected | property | The database connection. | |
OverviewForm:: |
protected | property | The Drupal module handler. | |
OverviewForm:: |
protected | property | The queue factory. | |
OverviewForm:: |
private | property | ||
OverviewForm:: |
private | property | ||
OverviewForm:: |
protected | property | The Drupal state storage. | |
OverviewForm:: |
protected | property | The tempstore factory. | |
OverviewForm:: |
public | function |
Form constructor. Overrides FormInterface:: |
|
OverviewForm:: |
public static | function |
Overrides FormBase:: |
|
OverviewForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
OverviewForm:: |
public | function | Process queue(s) with batch. | |
OverviewForm:: |
public | function | ||
OverviewForm:: |
public | function | Option to delete queue. | |
OverviewForm:: |
public | function |
We need this method, but each button has its own submit handler. Overrides FormInterface:: |
|
OverviewForm:: |
public | function | Option to remove lease timestamps. | |
OverviewForm:: |
public | function | OverviewForm constructor. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |