class DigestIntervalActionDeriver in Message Digest 8
Derives action plugins for changing digest intervals.
Hierarchy
- class \Drupal\Component\Plugin\Derivative\DeriverBase implements DeriverInterface
- class \Drupal\message_digest_ui\Plugin\Derivative\DigestIntervalActionDeriver implements ContainerDeriverInterface uses StringTranslationTrait
Expanded class hierarchy of DigestIntervalActionDeriver
File
- message_digest_ui/
src/ Plugin/ Derivative/ DigestIntervalActionDeriver.php, line 15
Namespace
Drupal\message_digest_ui\Plugin\DerivativeView source
class DigestIntervalActionDeriver extends DeriverBase implements ContainerDeriverInterface {
use StringTranslationTrait;
/**
* The message notifier plugin manager.
*
* @var \Drupal\message_notify\Plugin\Notifier\Manager
*/
protected $messageNotifier;
/**
* The message subscribe email manager service.
*
* @var \Drupal\message_subscribe_email\Manager
*/
protected $subscribeManager;
/**
* Constructs the action deriver.
*
* @param \Drupal\message_notify\Plugin\Notifier\Manager $message_notifier
* The notifier plugin manager.
*/
public function __construct(Manager $message_notifier) {
$this->messageNotifier = $message_notifier;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($container
->get('plugin.message_notify.notifier.manager'));
}
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions($base_plugin_definition) {
// This is called very early during installation, and the flag service
// is not completely ready, so these are hardcoded for the time being.
$flags = [
'email_node' => 'node',
'email_term' => 'taxonomy_term',
'email_user' => 'user',
];
foreach ($flags as $flag_id => $entity_type_id) {
// Create a set of actions for each email flag/entity combination.
$plugin = [
'type' => $entity_type_id,
];
foreach ($this
->getDigestNotifiers() as $plugin_id => $label) {
$id = $flag_id . ':' . ($plugin_id ?: 'immediate');
$plugin['label'] = $label;
$plugin['id'] = $id;
$this->derivatives[$id] = $plugin + $base_plugin_definition;
}
}
return parent::getDerivativeDefinitions($base_plugin_definition);
}
/**
* Helper method to get digest notifiers.
*
* Also appends the 'send immediately' non-plugin.
*/
protected function getDigestNotifiers() {
$values = [
$this
->t('Send immediately'),
];
foreach ($this->messageNotifier
->getDefinitions() as $plugin_id => $plugin_definition) {
// Strip off the prefix.
$plugin_id = str_replace('message_digest:', '', $plugin_id);
if (is_subclass_of($plugin_definition['class'], DigestInterface::class)) {
$values[$plugin_id] = $plugin_definition['title'];
}
}
return $values;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DeriverBase:: |
protected | property | List of derivative definitions. | 1 |
DeriverBase:: |
public | function |
Gets the definition of a derivative plugin. Overrides DeriverInterface:: |
|
DigestIntervalActionDeriver:: |
protected | property | The message notifier plugin manager. | |
DigestIntervalActionDeriver:: |
protected | property | The message subscribe email manager service. | |
DigestIntervalActionDeriver:: |
public static | function |
Creates a new class instance. Overrides ContainerDeriverInterface:: |
|
DigestIntervalActionDeriver:: |
public | function |
Gets the definition of all derivatives of a base plugin. Overrides DeriverBase:: |
|
DigestIntervalActionDeriver:: |
protected | function | Helper method to get digest notifiers. | |
DigestIntervalActionDeriver:: |
public | function | Constructs the action deriver. | |
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. |