You are here

class LogCommentPermissions in Commerce Core 8.2

Hierarchy

Expanded class hierarchy of LogCommentPermissions

File

modules/log/src/LogCommentPermissions.php, line 10

Namespace

Drupal\commerce_log
View source
class LogCommentPermissions implements ContainerInjectionInterface {
  use StringTranslationTrait;

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

  /**
   * The log template manager.
   *
   * @var \Drupal\commerce_log\LogTemplateManagerInterface
   */
  protected $logTemplateManager;

  /**
   * Constructs a new CommentPermissions object.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   * @param \Drupal\commerce_log\LogTemplateManagerInterface $log_template_manager
   *   The log template manager.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager, LogTemplateManagerInterface $log_template_manager) {
    $this->entityTypeManager = $entity_type_manager;
    $this->logTemplateManager = $log_template_manager;
  }

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

  /**
   * Builds a list of permissions for entity types that support comments..
   *
   * @return array
   *   The permissions.
   */
  public function buildPermissions() {
    $permissions = [];
    foreach ($this->entityTypeManager
      ->getDefinitions() as $entity_type) {
      $entity_type_id = $entity_type
        ->id();
      $log_template_id = "{$entity_type_id}_admin_comment";
      if ($this->logTemplateManager
        ->hasDefinition($log_template_id)) {
        $permissions["add commerce_log {$entity_type_id} admin comment"] = [
          'title' => $this
            ->t('Add admin comments to @label', [
            '@label' => $entity_type
              ->getSingularLabel(),
          ]),
          'description' => $this
            ->t('Provides the ability to add admin comments to @label.', [
            '@label' => $entity_type
              ->getPluralLabel(),
          ]),
          'restrict access' => TRUE,
          'provider' => $entity_type
            ->getProvider(),
        ];
      }
    }
    return $permissions;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LogCommentPermissions::$entityTypeManager protected property The entity type manager.
LogCommentPermissions::$logTemplateManager protected property The log template manager.
LogCommentPermissions::buildPermissions public function Builds a list of permissions for entity types that support comments..
LogCommentPermissions::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
LogCommentPermissions::__construct public function Constructs a new CommentPermissions 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.