5 * Test module for the entity API providing several entity types for testing.
8 use Drupal\Core\Access\AccessResult;
9 use Drupal\Core\Entity\ContentEntityInterface;
10 use Drupal\Core\Entity\EntityInterface;
11 use Drupal\Core\Entity\FieldableEntityInterface;
12 use Drupal\Core\Entity\EntityTypeInterface;
13 use Drupal\Core\Field\BaseFieldDefinition;
14 use Drupal\Core\Field\FieldDefinitionInterface;
15 use Drupal\Core\Field\FieldItemListInterface;
16 use Drupal\Core\Field\FieldStorageDefinitionInterface;
17 use Drupal\Core\Form\FormStateInterface;
18 use Drupal\Core\Session\AccountInterface;
19 use Drupal\Core\Entity\Entity\EntityFormDisplay;
23 * Filter that limits test entity list to revisable ones.
25 const ENTITY_TEST_TYPES_REVISABLE = 1;
28 * Filter that limits test entity list to multilingual ones.
30 const ENTITY_TEST_TYPES_MULTILINGUAL = 2;
33 * Filter that limits test entity list to routeable ones.
35 const ENTITY_TEST_TYPES_ROUTING = 3;
38 * Returns a list of test entity types.
40 * The returned entity types are one for each available entity storage type:
41 * - The plain entity_test type supports neither revisions nor multilingual
43 * - The entity_test_mul type supports multilingual properties.
44 * - The entity_test_rev type supports revisions.
45 * - The entity_test_mulrev type supports both revisions and multilingual
49 * Either ENTITY_TEST_TYPES_REVISABLE to only return revisable entity types or
50 * ENTITY_TEST_TYPES_MULTILINGUAL to only return multilingual ones. Defaults
51 * to NULL, which returns all.
54 * List with entity_types.
56 function entity_test_entity_types($filter = NULL) {
58 if ($filter === NULL || $filter === ENTITY_TEST_TYPES_ROUTING) {
59 $types[] = 'entity_test';
61 if ($filter != ENTITY_TEST_TYPES_REVISABLE) {
62 $types[] = 'entity_test_mul';
63 $types[] = 'entity_test_mul_langcode_key';
64 $types[] = 'entity_test_mul_changed';
66 if ($filter != ENTITY_TEST_TYPES_MULTILINGUAL) {
67 $types[] = 'entity_test_rev';
69 if ($filter === ENTITY_TEST_TYPES_ROUTING) {
70 $types[] = 'entity_test_base_field_display';
71 $types[] = 'entity_test_string_id';
72 $types[] = 'entity_test_no_id';
74 $types[] = 'entity_test_mulrev';
75 $types[] = 'entity_test_mulrev_changed';
77 return array_combine($types, $types);
81 * Implements hook_entity_type_alter().
83 function entity_test_entity_type_alter(array &$entity_types) {
84 $state = \Drupal::state();
86 /** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */
87 foreach (entity_test_entity_types() as $entity_type) {
88 // Optionally specify a translation handler for testing translations.
89 if ($state->get('entity_test.translation')) {
90 $translation = $entity_types[$entity_type]->get('translation');
91 $translation[$entity_type] = TRUE;
92 $entity_types[$entity_type]->set('translation', $translation);
96 // Allow entity_test_with_bundle tests to override the entity type definition.
97 $entity_types['entity_test_with_bundle'] = $state->get('entity_test_with_bundle.entity_type', $entity_types['entity_test_with_bundle']);
99 // Enable the entity_test_new only when needed.
100 if (!$state->get('entity_test_new')) {
101 unset($entity_types['entity_test_new']);
106 * Implements hook_module_implements_alter().
108 function entity_test_module_implements_alter(&$implementations, $hook) {
109 // Move our hook_entity_type_alter() implementation to the beginning of the
110 // list in order to run before content_moderation_entity_type_alter().
111 if ($hook === 'entity_type_alter') {
112 $implementations = ['entity_test' => $implementations['entity_test']] + $implementations;
117 * Implements hook_entity_base_field_info().
119 function entity_test_entity_base_field_info(EntityTypeInterface $entity_type) {
122 if ($entity_type->id() == 'entity_test_mulrev' && \Drupal::state()->get('entity_test.field_test_item')) {
123 $fields['field_test_item'] = BaseFieldDefinition::create('field_test')
124 ->setLabel(t('Field test'))
125 ->setDescription(t('A field test.'))
126 ->setRevisionable(TRUE)
127 ->setTranslatable(TRUE);
129 if ($entity_type->id() == 'entity_test_mulrev' && \Drupal::state()->get('entity_test.multi_column')) {
130 $fields['description'] = BaseFieldDefinition::create('shape')
131 ->setLabel(t('Some custom description'))
132 ->setTranslatable(TRUE);
139 * Implements hook_entity_base_field_info_alter().
141 function entity_test_entity_base_field_info_alter(&$fields, EntityTypeInterface $entity_type) {
142 $state = \Drupal::state();
143 if ($entity_type->id() == 'entity_test_mulrev' && ($names = $state->get('entity_test.field_definitions.translatable'))) {
144 foreach ($names as $name => $value) {
145 $fields[$name]->setTranslatable($value);
148 if ($entity_type->id() == 'node' && $state->get('entity_test.node_remove_status_field')) {
149 unset($fields['status']);
151 if ($entity_type->id() == 'entity_test' && $state->get('entity_test.remove_name_field')) {
152 unset($fields['name']);
154 // In 8001 we are assuming that a new definition with multiple cardinality has
156 // @todo Remove this if we end up using state definitions at runtime. See
157 // https://www.drupal.org/node/2554235.
158 if ($entity_type->id() == 'entity_test' && $state->get('entity_test.db_updates.entity_definition_updates') == 8001) {
159 $fields['user_id']->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
164 * Creates a new bundle for entity_test entities.
166 * @param string $bundle
167 * The machine-readable name of the bundle.
168 * @param string $text
169 * (optional) The human-readable name of the bundle. If none is provided, the
170 * machine name will be used.
171 * @param string $entity_type
172 * (optional) The entity type for which the bundle is created. Defaults to
175 function entity_test_create_bundle($bundle, $text = NULL, $entity_type = 'entity_test') {
176 $bundles = \Drupal::state()->get($entity_type . '.bundles') ?: [$entity_type => ['label' => 'Entity Test Bundle']];
177 $bundles += [$bundle => ['label' => $text ? $text : $bundle]];
178 \Drupal::state()->set($entity_type . '.bundles', $bundles);
180 \Drupal::entityManager()->onBundleCreate($bundle, $entity_type);
184 * Deletes a bundle for entity_test entities.
186 * @param string $bundle
187 * The machine-readable name of the bundle to delete.
188 * @param string $entity_type
189 * (optional) The entity type for which the bundle is deleted. Defaults to
192 function entity_test_delete_bundle($bundle, $entity_type = 'entity_test') {
193 $bundles = \Drupal::state()->get($entity_type . '.bundles') ?: [$entity_type => ['label' => 'Entity Test Bundle']];
194 unset($bundles[$bundle]);
195 \Drupal::state()->set($entity_type . '.bundles', $bundles);
197 \Drupal::entityManager()->onBundleDelete($bundle, $entity_type);
201 * Implements hook_entity_bundle_info().
203 function entity_test_entity_bundle_info() {
205 $entity_types = \Drupal::entityManager()->getDefinitions();
206 foreach ($entity_types as $entity_type_id => $entity_type) {
207 if ($entity_type->getProvider() == 'entity_test' && $entity_type_id != 'entity_test_with_bundle') {
208 $bundles[$entity_type_id] = \Drupal::state()->get($entity_type_id . '.bundles') ?: [$entity_type_id => ['label' => 'Entity Test Bundle']];
215 * Implements hook_entity_view_mode_info_alter().
217 function entity_test_entity_view_mode_info_alter(&$view_modes) {
218 $entity_info = \Drupal::entityManager()->getDefinitions();
219 foreach ($entity_info as $entity_type => $info) {
220 if ($entity_info[$entity_type]->getProvider() == 'entity_test' && !isset($view_modes[$entity_type])) {
221 $view_modes[$entity_type] = [
223 'label' => t('Full object'),
228 'label' => t('Teaser'),
238 * Implements hook_entity_form_mode_info_alter().
240 function entity_test_entity_form_mode_info_alter(&$form_modes) {
241 $entity_info = \Drupal::entityManager()->getDefinitions();
242 foreach ($entity_info as $entity_type => $info) {
243 if ($entity_info[$entity_type]->getProvider() == 'entity_test') {
244 $form_modes[$entity_type] = [
246 'label' => t('Compact version'),
255 * Implements hook_entity_extra_field_info().
257 function entity_test_entity_extra_field_info() {
258 $extra['entity_test']['bundle_with_extra_fields'] = [
260 // Note: those extra fields do not currently display anything, they are
261 // just used in \Drupal\Tests\field_ui\Kernel\EntityDisplayTest to test
262 // the behavior of entity display objects.
263 'display_extra_field' => [
264 'label' => t('Display extra field'),
265 'description' => t('An extra field on the display side.'),
269 'display_extra_field_hidden' => [
270 'label' => t('Display extra field (hidden)'),
271 'description' => t('An extra field on the display side, hidden by default.'),
281 * Implements hook_form_BASE_FORM_ID_alter().
283 function entity_test_form_entity_test_form_alter(&$form) {
284 switch (\Drupal::state()->get('entity_test.form.validate.test')) {
286 $form['#validate'][] = 'entity_test_form_entity_test_form_validate';
287 $form['#validate'][] = 'entity_test_form_entity_test_form_validate_check';
291 $form['actions']['submit']['#validate'][] = 'entity_test_form_entity_test_form_validate';
296 * Validation handler for the entity_test entity form.
298 function entity_test_form_entity_test_form_validate(array &$form, FormStateInterface $form_state) {
299 $form['#entity_test_form_validate'] = TRUE;
303 * Validation handler for the entity_test entity form.
305 function entity_test_form_entity_test_form_validate_check(array &$form, FormStateInterface $form_state) {
306 if (!empty($form['#entity_test_form_validate'])) {
307 \Drupal::state()->set('entity_test.form.validate.result', TRUE);
312 * Implements hook_form_BASE_FORM_ID_alter().
314 function entity_test_form_node_form_alter(&$form, FormStateInterface $form_state, $form_id) {
315 $langcode = $form_state->getFormObject()->getFormLangcode($form_state);
316 \Drupal::state()->set('entity_test.form_langcode', $langcode);
320 * Loads a test entity.
325 * A boolean indicating that the internal cache should be reset.
327 * @return \Drupal\entity_test\Entity\EntityTest
328 * The loaded entity object, or NULL if the entity cannot be loaded.
330 function entity_test_load($id, $reset = FALSE) {
331 $storage = \Drupal::entityTypeManager()->getStorage('entity_test');
333 $storage->resetCache([$id]);
335 return $storage->load($id);
339 * Loads a test entity.
344 * A boolean indicating that the internal cache should be reset.
346 * @return \Drupal\entity_test\Entity\EntityTestRev
347 * The loaded entity object, or NULL if the entity cannot be loaded.
349 function entity_test_rev_load($id, $reset = FALSE) {
350 $storage = \Drupal::entityTypeManager()->getStorage('entity_test_rev');
352 $storage->resetCache([$id]);
354 return $storage->load($id);
358 * Loads a test entity.
363 * A boolean indicating that the internal cache should be reset.
365 * @return \Drupal\entity_test\Entity\EntityTestMul
366 * The loaded entity object, or FALSE if the entity cannot be loaded.
368 function entity_test_mul_load($id, $reset = FALSE) {
369 $storage = \Drupal::entityTypeManager()->getStorage('entity_test_mul');
371 $storage->resetCache([$id]);
373 return $storage->load($id);
377 * Loads a test entity.
382 * A boolean indicating that the internal cache should be reset.
384 * @return \Drupal\entity_test\Entity\EntityTestMulRev
385 * The loaded entity object, or NULL if the entity cannot be loaded.
387 function entity_test_mulrev_load($id, $reset = FALSE) {
388 $storage = \Drupal::entityTypeManager()->getStorage('entity_test_mulrev');
390 $storage->resetCache([$id]);
392 return $storage->load($id);
396 * Implements hook_ENTITY_TYPE_insert() for 'entity_test'.
398 function entity_test_entity_test_insert($entity) {
399 if ($entity->name->value == 'fail_insert') {
400 throw new Exception("Test exception rollback.");
405 * Implements hook_entity_insert().
407 function entity_test_entity_insert(EntityInterface $entity) {
408 if ($entity->getEntityTypeId() == 'entity_test_mulrev' && $entity->label() == 'EntityLoadedRevisionTest') {
409 $entity->setNewRevision(FALSE);
415 * Implements hook_entity_update().
417 function entity_test_entity_update(EntityInterface $entity) {
418 if ($entity instanceof ContentEntityInterface) {
419 \Drupal::state()->set('entity_test.loadedRevisionId', $entity->getLoadedRevisionId());
424 * Implements hook_entity_field_access().
426 * @see \Drupal\system\Tests\Entity\FieldAccessTest::testFieldAccess()
428 function entity_test_entity_field_access($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL) {
429 if ($field_definition->getName() == 'field_test_text') {
431 if ($items->value == 'no access value') {
432 return AccessResult::forbidden()->addCacheableDependency($items->getEntity());
434 elseif ($items->value == 'custom cache tag value') {
435 return AccessResult::allowed()->addCacheableDependency($items->getEntity())->addCacheTags(['entity_test_access:field_test_text']);
437 elseif ($operation == 'edit' && $items->value == 'no edit access value') {
438 return AccessResult::forbidden()->addCacheableDependency($items->getEntity());
442 if ($field = \Drupal::state()->get('views_field_access_test-field')) {
443 if ($field_definition->getName() === $field) {
444 $result = AccessResult::allowedIfHasPermission($account, 'view test entity field');
445 // For test purposes we want to actively deny access.
446 if ($result->isNeutral()) {
447 $result = AccessResult::forbidden();
454 return AccessResult::neutral();
458 * Implements hook_entity_field_access_alter().
460 * @see \Drupal\system\Tests\Entity\FieldAccessTest::testFieldAccess()
462 function entity_test_entity_field_access_alter(array &$grants, array $context) {
463 if ($context['field_definition']->getName() == 'field_test_text' && $context['items']->value == 'access alter value') {
464 $grants[':default'] = AccessResult::forbidden()->inheritCacheability($grants[':default'])->addCacheableDependency($context['items']->getEntity());
469 * Implements hook_entity_form_display_alter().
471 function entity_test_entity_form_display_alter(EntityFormDisplay $form_display, $context) {
472 // Make the field_test_text field 42 characters for entity_test_mul.
473 if ($context['entity_type'] == 'entity_test') {
474 if ($component_options = $form_display->getComponent('field_test_text')) {
475 $component_options['settings']['size'] = 42;
476 $form_display->setComponent('field_test_text', $component_options);
482 * Implements hook_entity_presave().
484 function entity_test_entity_presave(EntityInterface $entity) {
485 if (isset($GLOBALS['entity_test_throw_exception'])) {
486 throw new Exception('Entity presave exception', 1);
489 if ($entity->getEntityType()->id() == 'entity_view_display') {
490 $entity->setThirdPartySetting('entity_test', 'foo', 'bar');
495 * Implements hook_entity_predelete().
497 function entity_test_entity_predelete(EntityInterface $entity) {
498 if (isset($GLOBALS['entity_test_throw_exception'])) {
499 throw new Exception('Entity predelete exception', 2);
504 * Implements hook_entity_operation_alter().
506 function entity_test_entity_operation_alter(array &$operations, EntityInterface $entity) {
507 $valid_entity_type_ids = [
511 if (in_array($entity->getEntityTypeId(), $valid_entity_type_ids)) {
512 if (\Drupal::service('router.route_provider')->getRouteByName("entity.{$entity->getEntityTypeId()}.test_operation")) {
513 $operations['test_operation'] = [
514 'title' => format_string('Test Operation: @label', ['@label' => $entity->label()]),
515 'url' => Url::fromRoute("entity.{$entity->getEntityTypeId()}.test_operation", [$entity->getEntityTypeId() => $entity->id()]),
523 * Implements hook_entity_translation_create().
525 function entity_test_entity_translation_create(EntityInterface $translation) {
526 _entity_test_record_hooks('entity_translation_create', $translation->language()->getId());
530 * Implements hook_entity_translation_insert().
532 function entity_test_entity_translation_insert(EntityInterface $translation) {
533 _entity_test_record_hooks('entity_translation_insert', $translation->language()->getId());
537 * Implements hook_entity_translation_delete().
539 function entity_test_entity_translation_delete(EntityInterface $translation) {
540 _entity_test_record_hooks('entity_translation_delete', $translation->language()->getId());
544 * Implements hook_ENTITY_TYPE_translation_create() for 'entity_test_mul'.
546 function entity_test_entity_test_mul_translation_create(EntityInterface $translation) {
547 _entity_test_record_hooks('entity_test_mul_translation_create', $translation->language()->getId());
551 * Implements hook_ENTITY_TYPE_translation_insert() for 'entity_test_mul'.
553 function entity_test_entity_test_mul_translation_insert(EntityInterface $translation) {
554 _entity_test_record_hooks('entity_test_mul_translation_insert', $translation->language()->getId());
558 * Implements hook_ENTITY_TYPE_translation_delete() for 'entity_test_mul'.
560 function entity_test_entity_test_mul_translation_delete(EntityInterface $translation) {
561 _entity_test_record_hooks('entity_test_mul_translation_delete', $translation->language()->getId());
565 * Implements hook_ENTITY_TYPE_translation_create() for 'entity_test_mul_changed'.
567 function entity_test_entity_test_mul_changed_translation_create(EntityInterface $translation) {
568 _entity_test_record_hooks('entity_test_mul_changed_translation_create', $translation->language()->getId());
572 * Implements hook_ENTITY_TYPE_translation_insert() for 'entity_test_mul_changed'.
574 function entity_test_entity_test_mul_changed_translation_insert(EntityInterface $translation) {
575 _entity_test_record_hooks('entity_test_mul_changed_translation_insert', $translation->language()->getId());
579 * Implements hook_ENTITY_TYPE_translation_delete().
581 function entity_test_entity_test_mul_changed_translation_delete(EntityInterface $translation) {
582 _entity_test_record_hooks('entity_test_mul_changed_translation_delete', $translation->language()->getId());
586 * Implements hook_ENTITY_TYPE_translation_create().
588 function entity_test_entity_test_mulrev_translation_create(EntityInterface $translation) {
589 _entity_test_record_hooks('entity_test_mulrev_translation_create', $translation->language()->getId());
593 * Implements hook_ENTITY_TYPE_translation_insert().
595 function entity_test_entity_test_mulrev_translation_insert(EntityInterface $translation) {
596 _entity_test_record_hooks('entity_test_mulrev_translation_insert', $translation->language()->getId());
600 * Implements hook_ENTITY_TYPE_translation_delete() for 'entity_test_mulrev'.
602 function entity_test_entity_test_mulrev_translation_delete(EntityInterface $translation) {
603 _entity_test_record_hooks('entity_test_mulrev_translation_delete', $translation->language()->getId());
607 * Implements hook_ENTITY_TYPE_translation_create() for 'entity_test_mulrev_changed'.
609 function entity_test_entity_test_mulrev_changed_translation_create(EntityInterface $translation) {
610 _entity_test_record_hooks('entity_test_mulrev_changed_translation_create', $translation->language()->getId());
614 * Implements hook_ENTITY_TYPE_translation_insert() for 'entity_test_mulrev'.
616 function entity_test_entity_test_mulrev_changed_translation_insert(EntityInterface $translation) {
617 _entity_test_record_hooks('entity_test_mulrev_changed_translation_insert', $translation->language()->getId());
621 * Implements hook_ENTITY_TYPE_translation_delete().
623 function entity_test_entity_test_mulrev_changed_translation_delete(EntityInterface $translation) {
624 _entity_test_record_hooks('entity_test_mulrev_changed_translation_delete', $translation->language()->getId());
628 * Implements hook_ENTITY_TYPE_translation_create() for 'entity_test_mul_langcode_key'.
630 function entity_test_entity_test_mul_langcode_key_translation_create(EntityInterface $translation) {
631 _entity_test_record_hooks('entity_test_mul_langcode_key_translation_create', $translation->language()->getId());
635 * Implements hook_ENTITY_TYPE_translation_insert() for 'entity_test_mul_langcode_key'.
637 function entity_test_entity_test_mul_langcode_key_translation_insert(EntityInterface $translation) {
638 _entity_test_record_hooks('entity_test_mul_langcode_key_translation_insert', $translation->language()->getId());
642 * Implements hook_ENTITY_TYPE_translation_delete() for 'entity_test_mul_langcode_key'.
644 function entity_test_entity_test_mul_langcode_key_translation_delete(EntityInterface $translation) {
645 _entity_test_record_hooks('entity_test_mul_langcode_key_translation_delete', $translation->language()->getId());
649 * Field default value callback.
651 * @param \Drupal\Core\Entity\FieldableEntityInterface $entity
652 * The entity being created.
653 * @param \Drupal\Core\Field\FieldDefinitionInterface $definition
654 * The field definition.
657 * An array of default values, in the same format as the $default_value
660 * @see \Drupal\field\Entity\FieldConfig::$default_value
662 function entity_test_field_default_value(FieldableEntityInterface $entity, FieldDefinitionInterface $definition) {
663 // Include the field name and entity language in the generated values to check
664 // that they are correctly passed.
665 $string = $definition->getName() . '_' . $entity->language()->getId();
666 // Return a "default value" with multiple items.
669 'shape' => "shape:0:$string",
670 'color' => "color:0:$string",
673 'shape' => "shape:1:$string",
674 'color' => "color:1:$string",
680 * Helper function to be used to record hook invocations.
682 * @param string $hook
685 * Arbitrary data associated with the hook invocation.
687 function _entity_test_record_hooks($hook, $data) {
688 $state = \Drupal::state();
689 $key = 'entity_test.hooks';
690 $hooks = $state->get($key);
691 $hooks[$hook] = $data;
692 $state->set($key, $hooks);
696 * Implements hook_entity_prepare_view().
698 function entity_test_entity_prepare_view($entity_type, array $entities, array $displays) {
699 if ($entity_type == 'entity_test') {
700 foreach ($entities as $entity) {
701 /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
703 // Add a dummy field item attribute on field_test_text if it exists.
704 if ($entity->hasField('field_test_text') && $displays[$entity->bundle()]->getComponent('field_test_text')) {
705 foreach ($entity->get('field_test_text') as $item) {
706 $item->_attributes += ['data-field-item-attr' => 'foobar'];
710 // Add a dummy field item attribute on daterange fields if they exist.
711 $fields = $entity->getFieldDefinitions();
712 foreach ($fields as $field) {
713 if ($field->getType() === 'daterange') {
714 $item = $entity->get($field->getName());
715 $item->_attributes += ['data-field-item-attr' => 'foobar'];
723 * Implements hook_entity_display_build_alter().
725 function entity_test_entity_display_build_alter(&$build, $context) {
726 /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
727 $entity = $context['entity'];
728 if ($entity->getEntityTypeId() == 'entity_test' && $entity->bundle() == 'display_build_alter_bundle') {
729 $build['entity_display_build_alter']['#markup'] = 'Content added in hook_entity_display_build_alter for entity id ' . $entity->id();
734 * Implements hook_entity_access().
736 function entity_test_entity_access(EntityInterface $entity, $operation, AccountInterface $account) {
737 // Only apply to the 'entity_test' entities.
738 if ($entity->getEntityType()->getProvider() != 'entity_test') {
739 return AccessResult::neutral();
741 \Drupal::state()->set('entity_test_entity_access', TRUE);
743 // Attempt to allow access to entities with the title forbid_access,
744 // this will be overridden by
745 // \Drupal\entity_test\EntityTestAccessControlHandler::checkAccess().
746 if ($entity->label() == 'forbid_access') {
747 return AccessResult::allowed();
750 // Create specific labels to allow or deny access based on certain test
752 // @see \Drupal\KernelTests\Core\Entity\EntityAccessControlHandlerTest
753 if ($entity->label() == 'Accessible') {
754 return AccessResult::allowed();
756 if ($entity->label() == 'Inaccessible') {
757 return AccessResult::forbidden();
760 // Uncacheable because the access result depends on a State key-value pair and
761 // might therefore change at any time.
762 $condition = \Drupal::state()->get("entity_test_entity_access.{$operation}." . $entity->id(), FALSE);
763 return AccessResult::allowedIf($condition)->setCacheMaxAge(0);
767 * Implements hook_ENTITY_TYPE_access() for 'entity_test'.
769 function entity_test_entity_test_access(EntityInterface $entity, $operation, AccountInterface $account) {
770 \Drupal::state()->set('entity_test_entity_test_access', TRUE);
773 return AccessResult::neutral();
777 * Implements hook_entity_create_access().
779 function entity_test_entity_create_access(AccountInterface $account, $context, $entity_bundle) {
780 \Drupal::state()->set('entity_test_entity_create_access', TRUE);
781 \Drupal::state()->set('entity_test_entity_create_access_context', $context);
784 return AccessResult::neutral();
788 * Implements hook_ENTITY_TYPE_create_access() for 'entity_test'.
790 function entity_test_entity_test_create_access(AccountInterface $account, $context, $entity_bundle) {
791 \Drupal::state()->set('entity_test_entity_test_create_access', TRUE);
794 return AccessResult::neutral();