You are here

public function GroupContentEnablerBase::checkAccess in Group 8

Checks access to an operation on a given group content entity.

Use \Drupal\group\Plugin\GroupContentEnablerInterface::createAccess() to check access to create a group content entity.

Parameters

\Drupal\group\Entity\GroupContentInterface $group_content: The group content for which to check access.

string $operation: The operation access should be checked for. Usually one of "view", "update" or "delete".

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

Return value

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

Overrides GroupContentEnablerInterface::checkAccess

Deprecated

in Group 1.0, will be removed before Group 2.0. Retrieve the access handler from the plugin manager instead.

File

src/Plugin/GroupContentEnablerBase.php, line 388

Class

GroupContentEnablerBase
Provides a base class for GroupContentEnabler plugins.

Namespace

Drupal\group\Plugin

Code

public function checkAccess(GroupContentInterface $group_content, $operation, AccountInterface $account) {

  /** @var \Drupal\group\Plugin\GroupContentEnablerManagerInterface $manager */
  $manager = \Drupal::service('plugin.manager.group_content_enabler');

  // Backwards compatibility layer:
  // - Use the declared access control handler if available.
  if ($manager
    ->hasHandler($this->pluginId, 'access')) {
    return $manager
      ->getAccessControlHandler($this->pluginId)
      ->relationAccess($group_content, $operation, $account, TRUE);
  }

  // Backwards compatibility layer:
  // - Run the old code if there is no access control handler.
  switch ($operation) {
    case 'view':
      $result = $this
        ->viewAccess($group_content, $account);
      break;
    case 'update':
      $result = $this
        ->updateAccess($group_content, $account);
      break;
    case 'delete':
      $result = $this
        ->deleteAccess($group_content, $account);
      break;
    default:
      $result = GroupAccessResult::neutral();
  }
  return $result;
}