You are here

class Permissions in Courier 8

Same name and namespace in other branches
  1. 2.x courier_message_composer/src/Permissions.php \Drupal\courier_message_composer\Permissions

Define a permission generator for Courier Message Composer.

Hierarchy

Expanded class hierarchy of Permissions

File

courier_message_composer/src/Permissions.php, line 14

Namespace

Drupal\courier_message_composer
View source
class Permissions implements ContainerInjectionInterface {
  use StringTranslationTrait;

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * The identity channel manager.
   *
   * @var \Drupal\courier\Service\IdentityChannelManager
   */
  protected $identityChannelManager;

  /**
   * Constructs a CourierMessageController object.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   * @param \Drupal\courier\Service\IdentityChannelManagerInterface $identity_channel_manager
   *   The identity channel manager.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager, IdentityChannelManagerInterface $identity_channel_manager) {
    $this->entityTypeManager = $entity_type_manager;
    $this->identityChannelManager = $identity_channel_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('entity_type.manager'), $container
      ->get('plugin.manager.identity_channel'));
  }

  /**
   * Define permissions for each channel + identity combination.
   *
   * @return array
   */
  public function sendMessageToChannels() {
    $permissions = [];
    $t_args = [];
    foreach ($this->identityChannelManager
      ->getChannels() as $channel => $identity_types) {
      $t_args['%channel'] = $this->entityTypeManager
        ->getDefinition($channel)
        ->getLabel();
      foreach ($identity_types as $identity) {
        $t_args['%identity'] = $this->entityTypeManager
          ->getDefinition($identity)
          ->getLabel();
        $permissions["courier_message_composer compose {$channel} to {$identity}"] = [
          'title' => $this
            ->t('Send %channel to %identity', $t_args),
          'description' => $this
            ->t('Send individual messages to any %identity.', $t_args),
        ];
      }
    }
    return $permissions;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Permissions::$entityTypeManager protected property The entity type manager.
Permissions::$identityChannelManager protected property The identity channel manager.
Permissions::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
Permissions::sendMessageToChannels public function Define permissions for each channel + identity combination.
Permissions::__construct public function Constructs a CourierMessageController object.
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.