You are here

function content_access_own_op in Content Access 8

Same name and namespace in other branches
  1. 6 content_access.module \content_access_own_op()
  2. 7 content_access.module \content_access_own_op()

Determines grant for node author and the gives allowed roles of operation.

Parameters

array $any_roles: The roles with which anybody has access (not optimized!).

array $own_roles: The roles with which only the author has access (optimized!).

Return value

int Returns 0 if permission is granted, otherwise 1.

2 calls to content_access_own_op()
content_access_get_type_grant in ./content_access.module
Returns the default grants for a given node type.
content_access_node_access_records in ./content_access.module
Implements hook_node_access_records().

File

./content_access.module, line 399
Content access module file.

Code

function content_access_own_op(NodeInterface $node, array $any_roles, array $own_roles) {
  static $roles = [];
  $owner = $node
    ->getOwner();
  if (!isset($roles[$owner
    ->id()])) {
    $roles[$owner
      ->id()] = $owner
      ->id() ? [
      AccountInterface::AUTHENTICATED_ROLE,
    ] : [
      AccountInterface::ANONYMOUS_ROLE,
    ];
    $result = $owner
      ->get('roles');
    foreach ($result as $role) {
      $roles[$owner
        ->id()][] = $role->target_id;
    }
  }
  if (array_intersect($roles[$owner
    ->id()], $any_roles)) {

    // If there is access due to "any permissions" there is no need to
    // add an author grant.
    return 0;
  }
  return array_intersect($roles[$owner
    ->id()], $own_roles) ? 1 : 0;
}