class ActionsPermissions in Views Bulk Operations (VBO) 8
Same name and namespace in other branches
- 8.3 modules/actions_permissions/src/ActionsPermissions.php \Drupal\actions_permissions\ActionsPermissions
- 8.2 modules/actions_permissions/src/ActionsPermissions.php \Drupal\actions_permissions\ActionsPermissions
- 4.0.x modules/actions_permissions/src/ActionsPermissions.php \Drupal\actions_permissions\ActionsPermissions
Create permissions for existing actions.
Hierarchy
- class \Drupal\actions_permissions\ActionsPermissions implements ContainerInjectionInterface uses StringTranslationTrait
Expanded class hierarchy of ActionsPermissions
File
- modules/
actions_permissions/ src/ ActionsPermissions.php, line 14
Namespace
Drupal\actions_permissionsView source
class ActionsPermissions implements ContainerInjectionInterface {
use StringTranslationTrait;
/**
* VBO Action manager service.
*
* @var \Drupal\views_bulk_operations\Service\ViewsBulkOperationsActionManager
*/
protected $actionManager;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Constructor.
*
* @param \Drupal\views_bulk_operations\Service\ViewsBulkOperationsActionManager $actionManager
* The action manager.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* Entity type manager.
*/
public function __construct(ViewsBulkOperationsActionManager $actionManager, EntityTypeManagerInterface $entityTypeManager) {
$this->actionManager = $actionManager;
$this->entityTypeManager = $entityTypeManager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('plugin.manager.views_bulk_operations_action'), $container
->get('entity_type.manager'));
}
/**
* Get permissions for Actions.
*
* @return array
* Permissions array.
*/
public function permissions() {
$permissions = [];
$entity_type_definitions = $this->entityTypeManager
->getDefinitions();
// Get definitions that will not be altered by actions_permissions.
foreach ($this->actionManager
->getDefinitions([
'skip_actions_permissions' => TRUE,
'nocache' => TRUE,
]) as $definition) {
// Skip actions that define their own requirements.
if (!empty($definition['requirements'])) {
continue;
}
$id = 'execute ' . $definition['id'];
$entity_type = NULL;
if (empty($definition['type'])) {
$entity_type = $this
->t('all entity types');
$id .= ' all';
}
elseif (isset($entity_type_definitions[$definition['type']])) {
$entity_type = $entity_type_definitions[$definition['type']]
->getLabel();
$id .= ' ' . $definition['type'];
}
if (isset($entity_type)) {
$permissions[$id] = [
'title' => $this
->t('Execute the %action action on %type.', [
'%action' => $definition['label'],
'%type' => $entity_type,
]),
];
}
}
// Rebuild VBO action definitions cache with
// included action_permissions modifications.
$this->actionManager
->getDefinitions([
'nocache' => TRUE,
]);
return $permissions;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ActionsPermissions:: |
protected | property | VBO Action manager service. | |
ActionsPermissions:: |
protected | property | The entity type manager. | |
ActionsPermissions:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
ActionsPermissions:: |
public | function | Get permissions for Actions. | |
ActionsPermissions:: |
public | function | Constructor. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |