abstract class MessagePurgeBase in Message 8
Base implementation for MessagePurge plugins.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\message\MessagePurgeBase implements ContainerFactoryPluginInterface, MessagePurgeInterface uses StringTranslationTrait
Expanded class hierarchy of MessagePurgeBase
2 files declare their use of MessagePurgeBase
File
- src/
MessagePurgeBase.php, line 16
Namespace
Drupal\messageView source
abstract class MessagePurgeBase extends PluginBase implements MessagePurgeInterface, ContainerFactoryPluginInterface {
use StringTranslationTrait;
/**
* The weight of the purge plugin.
*
* @var int|string
*/
protected $weight = 0;
/**
* The entity query object for Message items.
*
* @var \Drupal\Core\Entity\Query\QueryInterface
*/
protected $messageQuery;
/**
* The message deletion queue.
*
* @var \Drupal\Core\Queue\QueueInterface
*/
protected $queue;
/**
* Constructs a MessagePurgeBase object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin ID for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Entity\Query\QueryInterface $message_query
* The entity query object for message items.
* @param \Drupal\Core\Queue\QueueInterface $queue
* The message deletion queue.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, QueryInterface $message_query, QueueInterface $queue) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->messageQuery = $message_query;
$this->queue = $queue;
$this
->setConfiguration($configuration);
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('entity_type.manager')
->getStorage('message')
->getQuery(), $container
->get('queue')
->get('message_delete'));
}
/**
* {@inheritdoc}
*/
public function process(array $ids) {
if (!empty($ids)) {
foreach (array_chunk($ids, MessagePurgeInterface::MESSAGE_DELETE_SIZE) as $queue_set) {
$this->queue
->createItem($queue_set);
}
}
}
/**
* Get a base query.
*
* @param \Drupal\message\MessageTemplateInterface $template
* The message template for which to fetch messages.
*
* @return \Drupal\Core\Entity\Query\QueryInterface
* The query object.
*/
protected function baseQuery(MessageTemplateInterface $template) {
return $this->messageQuery
->condition('template', $template
->id())
->sort('created', 'DESC')
->sort('mid', 'DESC');
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
return $form;
}
/**
* {@inheritdoc}
*/
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
}
/**
* {@inheritdoc}
*/
public function label() {
return $this->pluginDefinition['label'];
}
/**
* {@inheritdoc}
*/
public function description() {
return $this->pluginDefinition['description'];
}
/**
* {@inheritdoc}
*/
public function setWeight($weight) {
$this->weight = $weight;
return $this;
}
/**
* {@inheritdoc}
*/
public function getWeight() {
return $this->weight;
}
/**
* {@inheritdoc}
*/
public function getConfiguration() {
return [
'id' => $this
->getPluginId(),
'weight' => $this
->getWeight(),
'data' => $this->configuration,
];
}
/**
* {@inheritdoc}
*/
public function setConfiguration(array $configuration) {
$configuration += [
'data' => [],
'weight' => 0,
];
$this->configuration = $configuration['data'] + $this
->defaultConfiguration();
$this->weight = $configuration['weight'];
return $this;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigurableInterface:: |
public | function | Gets default configuration for this plugin. | 11 |
MessagePurgeBase:: |
protected | property | The entity query object for Message items. | |
MessagePurgeBase:: |
protected | property | The message deletion queue. | |
MessagePurgeBase:: |
protected | property | The weight of the purge plugin. | |
MessagePurgeBase:: |
protected | function | Get a base query. | |
MessagePurgeBase:: |
public | function |
Form constructor. Overrides PluginFormInterface:: |
2 |
MessagePurgeBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
1 |
MessagePurgeBase:: |
public | function |
Returns the purge method description. Overrides MessagePurgeInterface:: |
|
MessagePurgeBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
MessagePurgeBase:: |
public | function |
Returns the weight of the purge plugin. Overrides MessagePurgeInterface:: |
|
MessagePurgeBase:: |
public | function |
Returns the purge method label. Overrides MessagePurgeInterface:: |
|
MessagePurgeBase:: |
public | function |
Process the purgeable messages. Overrides MessagePurgeInterface:: |
|
MessagePurgeBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
MessagePurgeBase:: |
public | function |
Sets the weight for this purge plugin. Overrides MessagePurgeInterface:: |
|
MessagePurgeBase:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
2 |
MessagePurgeBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
|
MessagePurgeBase:: |
public | function |
Constructs a MessagePurgeBase object. Overrides PluginBase:: |
1 |
MessagePurgeInterface:: |
public | function | Fetch the messages that need to be purged for a given template. | 2 |
MessagePurgeInterface:: |
constant | The maximum number of messages that a queue worker should delete at once. | ||
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
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. |