public function PermissionEvent::setPermission in Organic groups 8
Sets the permission with the given data.
Parameters
\Drupal\og\PermissionInterface $permission: The permission to set.
Throws
\InvalidArgumentException Thrown when the permission has no name or title.
Overrides PermissionEventInterface::setPermission
1 call to PermissionEvent::setPermission()
- PermissionEvent::setPermissions in src/
Event/ PermissionEvent.php - Sets multiple permissions.
File
- src/
Event/ PermissionEvent.php, line 110
Class
- PermissionEvent
- Event that is fired when OG permissions are compiled.
Namespace
Drupal\og\EventCode
public function setPermission(PermissionInterface $permission) {
if (empty($permission
->getName())) {
throw new \InvalidArgumentException('Permission name is required.');
}
if (empty($permission
->getTitle())) {
throw new \InvalidArgumentException('The permission title is required.');
}
if ($permission instanceof GroupContentOperationPermission) {
// GroupContentOperationPermissions are uniquely identified by entity
// type, bundle, operation and ownership. Check if these properties are
// set.
if (empty($permission
->getEntityType())) {
throw new \InvalidArgumentException('The entity type ID is required.');
}
if (empty($permission
->getBundle())) {
throw new \InvalidArgumentException('The bundle ID is required.');
}
if (empty($permission
->getOperation())) {
throw new \InvalidArgumentException('The operation is required.');
}
// Check if this permission was already registered under another name, and
// remove it so the new one replaces it.
try {
$this
->deleteGroupContentOperationPermission($permission
->getEntityType(), $permission
->getBundle(), $permission
->getOperation(), $permission
->getOwner());
} catch (\InvalidArgumentException $e) {
// The permission wasn't set. There is nothing to delete.
}
}
$this->permissions[$permission
->getName()] = $permission;
}