You are here

class DigestDeriver in Message Digest 8

Derive message digest plugins for various intervals.

Hierarchy

Expanded class hierarchy of DigestDeriver

File

src/Plugin/Deriver/DigestDeriver.php, line 14

Namespace

Drupal\message_digest\Plugin\Deriver
View source
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);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DeriverBase::$derivatives protected property List of derivative definitions. 1
DeriverBase::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition
DigestDeriver::$entityTypeManager protected property The entity type manager.
DigestDeriver::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
DigestDeriver::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
DigestDeriver::__construct public function DigestDeriver constructor.
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.