Further modules included.
[yaffs-website] / web / modules / contrib / better_formats / src / BetterFormatsPermissions.php
1 <?php
2
3 namespace Drupal\better_formats;
4
5 use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
6 use Drupal\Core\Entity\EntityManagerInterface;
7 use Drupal\Core\StringTranslation\StringTranslationTrait;
8 use Symfony\Component\DependencyInjection\ContainerInterface;
9
10 /**
11  * Provides dynamic permissions of the better formats module.
12  */
13 class BetterFormatsPermissions implements ContainerInjectionInterface {
14
15   use StringTranslationTrait;
16
17   /**
18    * The entity manager.
19    *
20    * @var \Drupal\Core\Entity\EntityManagerInterface
21    */
22   protected $entityManager;
23
24   /**
25    * Constructs a new BetterFormatsPermissions instance.
26    *
27    * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
28    *   The entity manager.
29    */
30   public function __construct(EntityManagerInterface $entity_manager) {
31     $this->entityManager = $entity_manager;
32   }
33
34   /**
35    * {@inheritdoc}
36    */
37   public static function create(ContainerInterface $container) {
38     return new static($container->get('entity.manager'));
39   }
40
41   /**
42    * Returns an array of better formats permissions.
43    *
44    * @return array
45    */
46   public function permissions() {
47     $permissions = [];
48
49     // Generate permissions for each entity type.
50     foreach ($this->entityManager->getDefinitions() as $entity_type_id => $entity_type) {
51       if ($entity_type->get('field_ui_base_route')) {
52         $permissions['hide format selection for ' . $entity_type_id] = [
53           'title' => $this->t('Hide format selection for @label', ['@label' => $entity_type->getLabel()]),
54         ];
55       }
56     }
57
58     return $permissions;
59   }
60
61 }