comparison core/modules/field_ui/src/FieldUiPermissions.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 129ea1e6d783
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 namespace Drupal\field_ui;
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 field_ui module.
12 */
13 class FieldUiPermissions 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 FieldUiPermissions 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 field UI permissions.
43 *
44 * @return array
45 */
46 public function fieldPermissions() {
47 $permissions = [];
48
49 foreach ($this->entityManager->getDefinitions() as $entity_type_id => $entity_type) {
50 if ($entity_type->get('field_ui_base_route')) {
51 // Create a permission for each fieldable entity to manage
52 // the fields and the display.
53 $permissions['administer ' . $entity_type_id . ' fields'] = [
54 'title' => $this->t('%entity_label: Administer fields', ['%entity_label' => $entity_type->getLabel()]),
55 'restrict access' => TRUE,
56 ];
57 $permissions['administer ' . $entity_type_id . ' form display'] = [
58 'title' => $this->t('%entity_label: Administer form display', ['%entity_label' => $entity_type->getLabel()])
59 ];
60 $permissions['administer ' . $entity_type_id . ' display'] = [
61 'title' => $this->t('%entity_label: Administer display', ['%entity_label' => $entity_type->getLabel()])
62 ];
63 }
64 }
65
66 return $permissions;
67 }
68
69 }