--- /dev/null
+<?php
+
+/**
+ * @file
+ * Contains main module functionality.
+ */
+
+use Drupal\Core\Access\AccessResult;
+use Drupal\Core\Entity\EntityTypeInterface;
+use Drupal\Core\Field\BaseFieldDefinition;
+use Drupal\Core\Field\FieldDefinitionInterface;
+use Drupal\Core\Field\FieldItemListInterface;
+use Drupal\Core\Session\AccountInterface;
+
+
+/**
+ * Implements hook_entity_bundle_field_info().
+ */
+function views_entity_test_entity_base_field_info(EntityTypeInterface $entity_type) {
+ if ($entity_type->id() == 'entity_test') {
+ $definitions['test_text_access'] = BaseFieldDefinition::create('string')
+ ->setLabel(t('Test access'))
+ ->setTranslatable(FALSE)
+ ->setSetting('max_length', 64)
+ ->setDisplayOptions('form', [
+ 'type' => 'string_textfield',
+ 'weight' => 10,
+ ]);
+ return $definitions;
+ }
+}
+
+/**
+ * Implements hook_entity_field_access().
+ *
+ * @see \Drupal\system\Tests\Entity\FieldAccessTest::testFieldAccess()
+ */
+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();
+}