You are here

function domain_entity_entity_field_access in Domain Access Entity 8

Implements hook_entity_field_access().

File

./domain_entity.module, line 93
Enables domain access for entities, and access query alter.

Code

function domain_entity_entity_field_access($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL) {
  if ($field_definition
    ->getName() === DomainEntityMapper::FIELD_NAME && $operation == 'edit') {

    /** @var \Drupal\field\Entity\FieldConfig $field_definition */
    $behavior = $field_definition
      ->getThirdPartySetting('domain_entity', 'behavior', DomainEntityMapper::BEHAVIOR_AUTO);
    $access = AccessResult::allowedIfHasPermission($account, 'set domain access status for all entities');
    $access = $access
      ->orIf(AccessResult::allowedIf($behavior == DomainEntityMapper::BEHAVIOR_USER));
    $access
      ->addCacheableDependency($field_definition);

    // @todo Add remaining conditions.
    return $access;
  }
  return AccessResult::neutral();
}