trait PermissionProviderTrait in Group 2.0.x
Trait for group relation permission providers.
This trait takes care of common logic for permission providers. Please make sure your handler service asks for the entity_type.manager service and sets to the $this->entityTypeManager property in its constructor.
Hierarchy
- trait \Drupal\group\Plugin\Group\RelationHandler\PermissionProviderTrait uses RelationHandlerTrait
6 files declare their use of PermissionProviderTrait
- BarAdminPermissionProvider.php in tests/
modules/ group_test_plugin_alter/ src/ Plugin/ Group/ RelationHandler/ BarAdminPermissionProvider.php - BazAdminPermissionProvider.php in tests/
modules/ group_test_plugin_alter/ src/ Plugin/ Group/ RelationHandler/ BazAdminPermissionProvider.php - FooAdminPermissionProvider.php in tests/
modules/ group_test_plugin_alter/ src/ Plugin/ Group/ RelationHandler/ FooAdminPermissionProvider.php - FullEntityPermissionProvider.php in tests/
modules/ group_test_plugin/ src/ Plugin/ Group/ RelationHandler/ FullEntityPermissionProvider.php - GroupNodePermissionProvider.php in modules/
gnode/ src/ Plugin/ Group/ RelationHandler/ GroupNodePermissionProvider.php
File
- src/
Plugin/ Group/ RelationHandler/ PermissionProviderTrait.php, line 15
Namespace
Drupal\group\Plugin\Group\RelationHandlerView source
trait PermissionProviderTrait {
use RelationHandlerTrait {
init as traitInit;
}
/**
* The entity type the plugin handler is for.
*
* @var \Drupal\Core\Entity\EntityTypeInterface
*/
protected $entityType;
/**
* Whether the target entity type implements the EntityOwnerInterface.
*
* @var bool
*/
protected $implementsOwnerInterface;
/**
* Whether the target entity type implements the EntityPublishedInterface.
*
* @var bool
*/
protected $implementsPublishedInterface;
/**
* Whether the plugin defines permissions for the target entity type.
*
* @var bool
*/
protected $definesEntityPermissions;
/**
* {@inheritdoc}
*/
public function init($plugin_id, array $definition) {
$this
->traitInit($plugin_id, $definition);
$this->entityType = $this
->entityTypeManager()
->getDefinition($definition['entity_type_id']);
$this->implementsOwnerInterface = $this->entityType
->entityClassImplements(EntityOwnerInterface::class);
$this->implementsPublishedInterface = $this->entityType
->entityClassImplements(EntityPublishedInterface::class);
$this->definesEntityPermissions = !empty($definition['entity_access']);
}
/**
* {@inheritdoc}
*/
public function getAdminPermission() {
if (!isset($this->parent)) {
throw new \LogicException('Using PermissionProviderTrait without assigning a parent or overwriting the methods.');
}
return $this->parent
->getAdminPermission();
}
/**
* {@inheritdoc}
*/
public function getPermission($operation, $target, $scope = 'any') {
if (!isset($this->parent)) {
throw new \LogicException('Using PermissionProviderTrait without assigning a parent or overwriting the methods.');
}
return $this->parent
->getPermission($operation, $target, $scope);
}
/**
* {@inheritdoc}
*/
public function buildPermissions() {
if (!isset($this->parent)) {
throw new \LogicException('Using PermissionProviderTrait without assigning a parent or overwriting the methods.');
}
return $this->parent
->buildPermissions();
}
/**
* Builds a permission with common translation arguments predefined.
*
* @param string $title
* The permission title.
* @param string $description
* (optional) The permission description.
*
* @return array
* The permission with a default translatable markup replacement for both
* %plugin_name and %entity_type.
*/
protected function buildPermission($title, $description = NULL) {
$t_args = [
'%plugin_name' => $this->definition['label'],
'%entity_type' => $this->entityType
->getSingularLabel(),
];
$permission['title'] = $title;
$permission['title_args'] = $t_args;
if (isset($description)) {
$permission['description'] = $description;
$permission['description_args'] = $t_args;
}
return $permission;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PermissionProviderTrait:: |
protected | property | Whether the plugin defines permissions for the target entity type. | |
PermissionProviderTrait:: |
protected | property | The entity type the plugin handler is for. | |
PermissionProviderTrait:: |
protected | property | Whether the target entity type implements the EntityOwnerInterface. | |
PermissionProviderTrait:: |
protected | property | Whether the target entity type implements the EntityPublishedInterface. | |
PermissionProviderTrait:: |
protected | function | Builds a permission with common translation arguments predefined. | |
PermissionProviderTrait:: |
public | function | 4 | |
PermissionProviderTrait:: |
public | function | 4 | |
PermissionProviderTrait:: |
public | function | 4 | |
PermissionProviderTrait:: |
public | function | ||
RelationHandlerTrait:: |
protected | property | The plugin definition. | |
RelationHandlerTrait:: |
protected | property | The entity type manager. | |
RelationHandlerTrait:: |
protected | property | The group relation manager. | |
RelationHandlerTrait:: |
protected | property | The parent relation handler in the decorator chain. | |
RelationHandlerTrait:: |
protected | property | The plugin ID as read from the definition. | |
RelationHandlerTrait:: |
protected | function | Gets the entity type manager service. | |
RelationHandlerTrait:: |
protected | function | Gets the group relation manager service. | |
RelationHandlerTrait:: |
public | function | Aliased as: traitInit |