5 * Contains main module functionality.
8 use Drupal\Core\Access\AccessResult;
9 use Drupal\Core\Entity\EntityTypeInterface;
10 use Drupal\Core\Field\BaseFieldDefinition;
11 use Drupal\Core\Field\FieldDefinitionInterface;
12 use Drupal\Core\Field\FieldItemListInterface;
13 use Drupal\Core\Session\AccountInterface;
17 * Implements hook_entity_bundle_field_info().
19 function views_entity_test_entity_base_field_info(EntityTypeInterface $entity_type) {
20 if ($entity_type->id() == 'entity_test') {
21 $definitions['test_text_access'] = BaseFieldDefinition::create('string')
22 ->setLabel(t('Test access'))
23 ->setTranslatable(FALSE)
24 ->setSetting('max_length', 64)
25 ->setDisplayOptions('form', [
26 'type' => 'string_textfield',
34 * Implements hook_entity_field_access().
36 * @see \Drupal\system\Tests\Entity\FieldAccessTest::testFieldAccess()
38 function views_entity_test_entity_field_access($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL) {
39 if ($field_definition->getName() == 'test_text_access') {
41 if ($items->value == 'no access value') {
42 return AccessResult::forbidden()->addCacheableDependency($items->getEntity());
47 return AccessResult::neutral();