class RestPermissions
Same name in other branches
- 9 core/modules/rest/src/RestPermissions.php \Drupal\rest\RestPermissions
- 8.9.x core/modules/rest/src/RestPermissions.php \Drupal\rest\RestPermissions
- 11.x core/modules/rest/src/RestPermissions.php \Drupal\rest\RestPermissions
Provides rest module permissions.
Hierarchy
- class \Drupal\rest\RestPermissions implements \Drupal\Core\DependencyInjection\ContainerInjectionInterface
Expanded class hierarchy of RestPermissions
File
-
core/
modules/ rest/ src/ RestPermissions.php, line 14
Namespace
Drupal\restView source
class RestPermissions implements ContainerInjectionInterface {
/**
* The rest resource plugin manager.
*
* @var \Drupal\rest\Plugin\Type\ResourcePluginManager
*/
protected $restPluginManager;
/**
* The REST resource config storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $resourceConfigStorage;
/**
* Constructs a new RestPermissions instance.
*
* @param \Drupal\rest\Plugin\Type\ResourcePluginManager $rest_plugin_manager
* The rest resource plugin manager.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(ResourcePluginManager $rest_plugin_manager, EntityTypeManagerInterface $entity_type_manager) {
$this->restPluginManager = $rest_plugin_manager;
$this->resourceConfigStorage = $entity_type_manager->getStorage('rest_resource_config');
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container->get('plugin.manager.rest'), $container->get('entity_type.manager'));
}
/**
* Returns an array of REST permissions.
*
* @return array
*/
public function permissions() {
$permissions = [];
/** @var \Drupal\rest\RestResourceConfigInterface[] $resource_configs */
$resource_configs = $this->resourceConfigStorage
->loadMultiple();
foreach ($resource_configs as $resource_config) {
$plugin = $resource_config->getResourcePlugin();
// Add the rest resource configuration entity as a dependency to the
// permissions.
$permissions += array_map(function (array $permission_info) use ($resource_config) {
$merge_info['dependencies'][$resource_config->getConfigDependencyKey()] = [
$resource_config->getConfigDependencyName(),
];
return NestedArray::mergeDeep($permission_info, $merge_info);
}, $plugin->permissions());
}
return $permissions;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
RestPermissions::$resourceConfigStorage | protected | property | The REST resource config storage. | |
RestPermissions::$restPluginManager | protected | property | The rest resource plugin manager. | |
RestPermissions::create | public static | function | Instantiates a new instance of this class. | Overrides ContainerInjectionInterface::create |
RestPermissions::permissions | public | function | Returns an array of REST permissions. | |
RestPermissions::__construct | public | function | Constructs a new RestPermissions instance. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.