function MediaLibraryTestHooks::entityFieldAccess

Implements hook_entity_field_access().

File

core/modules/media_library/tests/modules/media_library_test/src/Hook/MediaLibraryTestHooks.php, line 35

Class

MediaLibraryTestHooks
Hook implementations for media_library_test.

Namespace

Drupal\media_library_test\Hook

Code

public function entityFieldAccess($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, ?FieldItemListInterface $items = NULL) {
    $deny_fields = \Drupal::state()->get('media_library_test_entity_field_access_deny_fields', []);
    // Always deny the field_media_no_access field.
    $deny_fields[] = 'field_media_no_access';
    return AccessResult::forbiddenIf(in_array($field_definition->getName(), $deny_fields, TRUE), 'Field access denied by test module');
}

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