Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/rest/src/RestPermissions.php @ 0:c75dbcec494b
Initial commit from drush-created site
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2018 14:24:15 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c75dbcec494b |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\rest; | |
4 | |
5 use Drupal\Core\DependencyInjection\ContainerInjectionInterface; | |
6 use Drupal\Core\Entity\EntityTypeManagerInterface; | |
7 use Drupal\rest\Plugin\Type\ResourcePluginManager; | |
8 use Symfony\Component\DependencyInjection\ContainerInterface; | |
9 | |
10 /** | |
11 * Provides rest module permissions. | |
12 */ | |
13 class RestPermissions implements ContainerInjectionInterface { | |
14 | |
15 /** | |
16 * The rest resource plugin manager. | |
17 * | |
18 * @var \Drupal\rest\Plugin\Type\ResourcePluginManager | |
19 */ | |
20 protected $restPluginManager; | |
21 | |
22 /** | |
23 * The REST resource config storage. | |
24 * | |
25 * @var \Drupal\Core\Entity\EntityManagerInterface | |
26 */ | |
27 protected $resourceConfigStorage; | |
28 | |
29 /** | |
30 * Constructs a new RestPermissions instance. | |
31 * | |
32 * @param \Drupal\rest\Plugin\Type\ResourcePluginManager $rest_plugin_manager | |
33 * The rest resource plugin manager. | |
34 * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager | |
35 * The entity type manager. | |
36 */ | |
37 public function __construct(ResourcePluginManager $rest_plugin_manager, EntityTypeManagerInterface $entity_type_manager) { | |
38 $this->restPluginManager = $rest_plugin_manager; | |
39 $this->resourceConfigStorage = $entity_type_manager->getStorage('rest_resource_config'); | |
40 } | |
41 | |
42 /** | |
43 * {@inheritdoc} | |
44 */ | |
45 public static function create(ContainerInterface $container) { | |
46 return new static($container->get('plugin.manager.rest'), $container->get('entity_type.manager')); | |
47 } | |
48 | |
49 /** | |
50 * Returns an array of REST permissions. | |
51 * | |
52 * @return array | |
53 */ | |
54 public function permissions() { | |
55 $permissions = []; | |
56 /** @var \Drupal\rest\RestResourceConfigInterface[] $resource_configs */ | |
57 $resource_configs = $this->resourceConfigStorage->loadMultiple(); | |
58 foreach ($resource_configs as $resource_config) { | |
59 $plugin = $resource_config->getResourcePlugin(); | |
60 $permissions = array_merge($permissions, $plugin->permissions()); | |
61 } | |
62 return $permissions; | |
63 } | |
64 | |
65 } |