BackendBase.php in Advanced Queue 8
File
src/Plugin/AdvancedQueue/Backend/BackendBase.php
View source
<?php
namespace Drupal\advancedqueue\Plugin\AdvancedQueue\Backend;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Plugin\PluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
abstract class BackendBase extends PluginBase implements BackendInterface, ContainerFactoryPluginInterface {
protected $time;
protected $queueId;
public function __construct(array $configuration, $plugin_id, $plugin_definition, TimeInterface $time) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->time = $time;
if (array_key_exists('_entity_id', $configuration)) {
$this->queueId = $configuration['_entity_id'];
unset($configuration['_entity_id']);
}
$this
->setConfiguration($configuration);
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('datetime.time'));
}
public function calculateDependencies() {
return [];
}
public function getConfiguration() {
return $this->configuration;
}
public function setConfiguration(array $configuration) {
$this->configuration = NestedArray::mergeDeep($this
->defaultConfiguration(), $configuration);
}
public function defaultConfiguration() {
return [
'lease_time' => 300,
];
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form['lease_time'] = [
'#type' => 'number',
'#title' => $this
->t('Lease time'),
'#description' => $this
->t('How long a job is reserved for processing.'),
'#field_suffix' => $this
->t('seconds'),
'#default_value' => $this->configuration['lease_time'],
'#min' => 1,
];
return $form;
}
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
}
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
if (!$form_state
->getErrors()) {
$values = $form_state
->getValue($form['#parents']);
$this->configuration = [];
$this->configuration['lease_time'] = $values['lease_time'];
}
}
public function getLabel() {
return (string) $this->pluginDefinition['label'];
}
public function cleanupQueue() {
}
}