LogCommentPermissions.php in Commerce Core 8.2
File
modules/log/src/LogCommentPermissions.php
View source
<?php
namespace Drupal\commerce_log;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
class LogCommentPermissions implements ContainerInjectionInterface {
use StringTranslationTrait;
protected $entityTypeManager;
protected $logTemplateManager;
public function __construct(EntityTypeManagerInterface $entity_type_manager, LogTemplateManagerInterface $log_template_manager) {
$this->entityTypeManager = $entity_type_manager;
$this->logTemplateManager = $log_template_manager;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('entity_type.manager'), $container
->get('plugin.manager.commerce_log_template'));
}
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;
}
}