class Days in Message 8
Delete messages older than certain days.
Plugin annotation
@MessagePurge(
id = "days",
label = @Translation("Days", context = "MessagePurge"),
description = @Translation("Delete messages older than a given amount of days."),
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\message\MessagePurgeBase implements ContainerFactoryPluginInterface, MessagePurgeInterface uses StringTranslationTrait
- class \Drupal\message\Plugin\MessagePurge\Days
- class \Drupal\message\MessagePurgeBase implements ContainerFactoryPluginInterface, MessagePurgeInterface uses StringTranslationTrait
Expanded class hierarchy of Days
1 file declares its use of Days
- DaysTest.php in tests/
src/ Unit/ Plugin/ MessagePurge/ DaysTest.php
1 string reference to 'Days'
- message.schema.yml in config/
schema/ message.schema.yml - config/schema/message.schema.yml
File
- src/
Plugin/ MessagePurge/ Days.php, line 23
Namespace
Drupal\message\Plugin\MessagePurgeView source
class Days extends MessagePurgeBase {
/**
* The request stack.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
protected $requestStack;
/**
* Days constructor.
*
* @param array $configuration
* The plugin configuration.
* @param string $plugin_id
* The plugin ID.
* @param mixed $plugin_definition
* The plugin definition.
* @param \Drupal\Core\Entity\Query\QueryInterface $message_query
* The entity query service.
* @param \Drupal\Core\Queue\QueueInterface $queue
* The message deletion queue.
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The request stack used to determine the current time.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, QueryInterface $message_query, QueueInterface $queue, RequestStack $request_stack) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $message_query, $queue);
$this->requestStack = $request_stack;
}
/**
* {@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'), $container
->get('request_stack'));
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form['days'] = [
'#type' => 'number',
'#min' => 1,
'#title' => $this
->t('Messages older than'),
'#description' => $this
->t('Maximal message age in days.'),
'#default_value' => $this->configuration['days'],
'#tree' => FALSE,
];
return parent::buildConfigurationForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
parent::submitConfigurationForm($form, $form_state);
$this->configuration['days'] = $form_state
->getValue('days');
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [
'days' => 30,
];
}
/**
* {@inheritdoc}
*/
public function fetch(MessageTemplateInterface $template) {
$query = $this
->baseQuery($template);
// Find messages older than the current time minus the maximum age.
$earlier_than = $this->requestStack
->getCurrentRequest()->server
->get('REQUEST_TIME') - $this->configuration['days'] * 86400;
$result = $query
->condition('created', $earlier_than, '<')
->execute();
return $result;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Days:: |
protected | property | The request stack. | |
Days:: |
public | function |
Form constructor. Overrides MessagePurgeBase:: |
|
Days:: |
public static | function |
Creates an instance of the plugin. Overrides MessagePurgeBase:: |
|
Days:: |
public | function |
Gets default configuration for this plugin. Overrides ConfigurableInterface:: |
|
Days:: |
public | function |
Fetch the messages that need to be purged for a given template. Overrides MessagePurgeInterface:: |
|
Days:: |
public | function |
Form submission handler. Overrides MessagePurgeBase:: |
|
Days:: |
public | function |
Days constructor. Overrides MessagePurgeBase:: |
|
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 |
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 validation handler. Overrides PluginFormInterface:: |
|
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. |