You are here

function views_entity_test_entity_field_access in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/views/tests/modules/views_entity_test/views_entity_test.module \views_entity_test_entity_field_access()

Implements hook_entity_field_access().

See also

\Drupal\system\Tests\Entity\FieldAccessTest::testFieldAccess()

File

core/modules/views/tests/modules/views_entity_test/views_entity_test.module, line 37
Contains main module functionality.

Code

function views_entity_test_entity_field_access($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL) {
  if ($field_definition
    ->getName() == 'test_text_access') {
    if ($items) {
      if ($items->value == 'no access value') {
        return AccessResult::forbidden()
          ->addCacheableDependency($items
          ->getEntity());
      }
    }
  }

  // No opinion.
  return AccessResult::neutral();
}