You are here

class PermissionManager in Organic groups 8

Manager for OG permissions.

Hierarchy

Expanded class hierarchy of PermissionManager

1 file declares its use of PermissionManager
OgAccessTestBase.php in tests/src/Unit/OgAccessTestBase.php
1 string reference to 'PermissionManager'
og.services.yml in ./og.services.yml
og.services.yml
1 service uses PermissionManager
og.permission_manager in ./og.services.yml
Drupal\og\PermissionManager

File

src/PermissionManager.php, line 14

Namespace

Drupal\og
View source
class PermissionManager implements PermissionManagerInterface {

  /**
   * The event dispatcher.
   *
   * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
   */
  protected $eventDispatcher;

  /**
   * Constructs a PermissionManager object.
   *
   * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
   *   The event dispatcher.
   */
  public function __construct(EventDispatcherInterface $event_dispatcher) {
    $this->eventDispatcher = $event_dispatcher;
  }

  /**
   * {@inheritdoc}
   */
  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();
  }

  /**
   * {@inheritdoc}
   */
  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) {

      // Only keep group permissions.
      if (!$permission instanceof GroupPermission) {
        return FALSE;
      }

      // Optionally filter on role name.
      $default_roles = $permission
        ->getDefaultRoles();
      return empty($role_name) || !empty($default_roles) && in_array($role_name, $permission
        ->getDefaultRoles());
    });
    return $permissions;
  }

  /**
   * {@inheritdoc}
   */
  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) {

      // Only keep entity operation permissions.
      if (!$permission instanceof GroupContentOperationPermission) {
        return FALSE;
      }

      // Optionally filter on role name.
      $default_roles = $permission
        ->getDefaultRoles();
      return empty($role_name) || !empty($default_roles) && in_array($role_name, $permission
        ->getDefaultRoles());
    });
    return $permissions;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PermissionManager::$eventDispatcher protected property The event dispatcher.
PermissionManager::getDefaultEntityOperationPermissions public function Returns the list of entity operation permissions for a given group content. Overrides PermissionManagerInterface::getDefaultEntityOperationPermissions
PermissionManager::getDefaultGroupPermissions public function Returns permissions that are enabled by default for the given role. Overrides PermissionManagerInterface::getDefaultGroupPermissions
PermissionManager::getDefaultPermissions public function Returns the full set of default permissions for a group and its content. Overrides PermissionManagerInterface::getDefaultPermissions
PermissionManager::__construct public function Constructs a PermissionManager object.