MessagePurgeBase.php in Message 8
File
src/MessagePurgeBase.php
View source
<?php
namespace Drupal\message;
use Drupal\Component\Plugin\PluginBase;
use Drupal\Core\Entity\Query\QueryInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Queue\QueueInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
abstract class MessagePurgeBase extends PluginBase implements MessagePurgeInterface, ContainerFactoryPluginInterface {
use StringTranslationTrait;
protected $weight = 0;
protected $messageQuery;
protected $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);
}
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'));
}
public function process(array $ids) {
if (!empty($ids)) {
foreach (array_chunk($ids, MessagePurgeInterface::MESSAGE_DELETE_SIZE) as $queue_set) {
$this->queue
->createItem($queue_set);
}
}
}
protected function baseQuery(MessageTemplateInterface $template) {
return $this->messageQuery
->condition('template', $template
->id())
->sort('created', 'DESC')
->sort('mid', 'DESC');
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
return $form;
}
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
}
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
}
public function label() {
return $this->pluginDefinition['label'];
}
public function description() {
return $this->pluginDefinition['description'];
}
public function setWeight($weight) {
$this->weight = $weight;
return $this;
}
public function getWeight() {
return $this->weight;
}
public function getConfiguration() {
return [
'id' => $this
->getPluginId(),
'weight' => $this
->getWeight(),
'data' => $this->configuration,
];
}
public function setConfiguration(array $configuration) {
$configuration += [
'data' => [],
'weight' => 0,
];
$this->configuration = $configuration['data'] + $this
->defaultConfiguration();
$this->weight = $configuration['weight'];
return $this;
}
}