function ViewsEntityTestHooks::entityFieldAccess

Implements hook_entity_field_access().

See also

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

File

core/modules/views/tests/modules/views_entity_test/src/Hook/ViewsEntityTestHooks.php, line 36

Class

ViewsEntityTestHooks
Hook implementations for views_entity_test.

Namespace

Drupal\views_entity_test\Hook

Code

public function entityFieldAccess($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();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.