AutoEntityLabelPermissionController.php in Automatic Entity Label 8.2
File
src/AutoEntityLabelPermissionController.php
View source
<?php
namespace Drupal\auto_entitylabel;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
class AutoEntityLabelPermissionController implements ContainerInjectionInterface {
use StringTranslationTrait;
protected $entityManager;
public function __construct(EntityTypeManagerInterface $entity_manager) {
$this->entityManager = $entity_manager;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('entity.manager'));
}
public function autoEntityLabelPermissions() {
$permissions = [];
foreach ($this->entityManager
->getDefinitions() as $entity_type_id => $entity_type) {
if ($entity_type
->hasLinkTemplate('auto-label') && $entity_type
->hasKey('label')) {
$permissions['administer ' . $entity_type_id . ' labels'] = [
'title' => $this
->t('%entity_label: Administer automatic entity labels', [
'%entity_label' => $entity_type
->getLabel(),
]),
'restrict access' => TRUE,
];
}
}
$permissions['use PHP for auto entity labels'] = [
'title' => $this
->t('Use PHP for automatic entity label patterns'),
'restrict access' => TRUE,
];
return $permissions;
}
}