DigestDeriver.php in Message Digest 8
Namespace
Drupal\message_digest\Plugin\DeriverFile
src/Plugin/Deriver/DigestDeriver.phpView source
<?php
namespace Drupal\message_digest\Plugin\Deriver;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Derive message digest plugins for various intervals.
*/
class DigestDeriver extends DeriverBase implements ContainerDeriverInterface {
use StringTranslationTrait;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* DigestDeriver constructor.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($container
->get('entity_type.manager'));
}
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions($base_plugin_definition) {
$this->derivatives = [];
foreach ($this->entityTypeManager
->getStorage('message_digest_interval')
->loadMultiple() as $id => $interval) {
/** @var \Drupal\message_digest\Entity\MessageDigestIntervalInterface $interval */
$this->derivatives[$id] = [
'id' => $id,
'title' => $interval
->label(),
'description' => $interval
->getDescription(),
'digest_interval' => $interval
->getInterval(),
];
$this->derivatives[$id] += $base_plugin_definition;
}
return parent::getDerivativeDefinitions($base_plugin_definition);
}
}
Classes
Name | Description |
---|---|
DigestDeriver | Derive message digest plugins for various intervals. |