You are here

protected function OpignoActivityAccessControlHandler::checkCreateAccess in Opigno module 3.x

Same name and namespace in other branches
  1. 8 src/OpignoActivityAccessControlHandler.php \Drupal\opigno_module\OpignoActivityAccessControlHandler::checkCreateAccess()

Performs create access checks.

This method is supposed to be overwritten by extending classes that do their own custom access checking.

Parameters

\Drupal\Core\Session\AccountInterface $account: The user for which to check access.

array $context: An array of key-value pairs to pass additional context when needed.

string|null $entity_bundle: (optional) The bundle of the entity. Required if the entity supports bundles, defaults to NULL otherwise.

Return value

\Drupal\Core\Access\AccessResultInterface The access result.

Overrides EntityAccessControlHandler::checkCreateAccess

File

src/OpignoActivityAccessControlHandler.php, line 69

Class

OpignoActivityAccessControlHandler
Access controller for the Activity entity.

Namespace

Drupal\opigno_module

Code

protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
  if ($account
    ->hasPermission('manage group content in any group')) {
    return AccessResult::allowed();
  }

  // Allow user to create activities
  // if the user is a group-level content manager in any group.
  $membership_service = \Drupal::service('group.membership_loader');
  $memberships = $membership_service
    ->loadByUser($account);
  foreach ($memberships as $membership) {

    /** @var \Drupal\group\GroupMembership $membership */
    $group = $membership
      ->getGroup();
    if ($group
      ->access('update', $account)) {
      return AccessResult::allowed();
    }
  }
  return AccessResult::allowedIfHasPermission($account, 'add activity entities');
}