You are here

abstract class MessagePurgeBase in Message 8

Base implementation for MessagePurge plugins.

Hierarchy

Expanded class hierarchy of MessagePurgeBase

2 files declare their use of MessagePurgeBase
Days.php in src/Plugin/MessagePurge/Days.php
Quota.php in src/Plugin/MessagePurge/Quota.php

File

src/MessagePurgeBase.php, line 16

Namespace

Drupal\message
View 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

Namesort descending Modifiers Type Description Overrides
ConfigurableInterface::defaultConfiguration public function Gets default configuration for this plugin. 11
MessagePurgeBase::$messageQuery protected property The entity query object for Message items.
MessagePurgeBase::$queue protected property The message deletion queue.
MessagePurgeBase::$weight protected property The weight of the purge plugin.
MessagePurgeBase::baseQuery protected function Get a base query.
MessagePurgeBase::buildConfigurationForm public function Form constructor. Overrides PluginFormInterface::buildConfigurationForm 2
MessagePurgeBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create 1
MessagePurgeBase::description public function Returns the purge method description. Overrides MessagePurgeInterface::description
MessagePurgeBase::getConfiguration public function Gets this plugin's configuration. Overrides ConfigurableInterface::getConfiguration
MessagePurgeBase::getWeight public function Returns the weight of the purge plugin. Overrides MessagePurgeInterface::getWeight
MessagePurgeBase::label public function Returns the purge method label. Overrides MessagePurgeInterface::label
MessagePurgeBase::process public function Process the purgeable messages. Overrides MessagePurgeInterface::process
MessagePurgeBase::setConfiguration public function Sets the configuration for this plugin instance. Overrides ConfigurableInterface::setConfiguration
MessagePurgeBase::setWeight public function Sets the weight for this purge plugin. Overrides MessagePurgeInterface::setWeight
MessagePurgeBase::submitConfigurationForm public function Form submission handler. Overrides PluginFormInterface::submitConfigurationForm 2
MessagePurgeBase::validateConfigurationForm public function Form validation handler. Overrides PluginFormInterface::validateConfigurationForm
MessagePurgeBase::__construct public function Constructs a MessagePurgeBase object. Overrides PluginBase::__construct 1
MessagePurgeInterface::fetch public function Fetch the messages that need to be purged for a given template. 2
MessagePurgeInterface::MESSAGE_DELETE_SIZE constant The maximum number of messages that a queue worker should delete at once.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.