PermissionManager.php in Organic groups 8
File
src/PermissionManager.php
View source
<?php
declare (strict_types=1);
namespace Drupal\og;
use Drupal\og\Event\PermissionEvent;
use Drupal\og\Event\PermissionEventInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class PermissionManager implements PermissionManagerInterface {
protected $eventDispatcher;
public function __construct(EventDispatcherInterface $event_dispatcher) {
$this->eventDispatcher = $event_dispatcher;
}
public function getDefaultPermissions($group_entity_type_id, $group_bundle_id, array $group_content_bundle_ids, $role_name = NULL) {
$event = new PermissionEvent($group_entity_type_id, $group_bundle_id, $group_content_bundle_ids);
$this->eventDispatcher
->dispatch(PermissionEventInterface::EVENT_NAME, $event);
return $event
->getPermissions();
}
public function getDefaultGroupPermissions($group_entity_type_id, $group_bundle_id, $role_name = NULL) {
$permissions = $this
->getDefaultPermissions($group_entity_type_id, $group_bundle_id, [], $role_name);
$permissions = array_filter($permissions, function (PermissionInterface $permission) use ($role_name) {
if (!$permission instanceof GroupPermission) {
return FALSE;
}
$default_roles = $permission
->getDefaultRoles();
return empty($role_name) || !empty($default_roles) && in_array($role_name, $permission
->getDefaultRoles());
});
return $permissions;
}
public function getDefaultEntityOperationPermissions($group_entity_type_id, $group_bundle_id, array $group_content_bundle_ids, $role_name = NULL) {
$permissions = $this
->getDefaultPermissions($group_entity_type_id, $group_bundle_id, $group_content_bundle_ids, $role_name);
$permissions = array_filter($permissions, function (PermissionInterface $permission) use ($role_name) {
if (!$permission instanceof GroupContentOperationPermission) {
return FALSE;
}
$default_roles = $permission
->getDefaultRoles();
return empty($role_name) || !empty($default_roles) && in_array($role_name, $permission
->getDefaultRoles());
});
return $permissions;
}
}