Same name and namespace in other branches
  1. 8.9.x core/modules/system/tests/modules/entity_test/entity_test.module \entity_test_entity_create_access()
  2. 9 core/modules/system/tests/modules/entity_test/entity_test.module \entity_test_entity_create_access()

Implements hook_entity_create_access().

1 string reference to 'entity_test_entity_create_access'
EntityAccessControlHandlerTest::testHooks in core/tests/Drupal/KernelTests/Core/Entity/EntityAccessControlHandlerTest.php
Tests hook invocations.

File

core/modules/system/tests/modules/entity_test/entity_test.module, line 785
Test module for the entity API providing several entity types for testing.

Code

function entity_test_entity_create_access(AccountInterface $account, $context, $entity_bundle) {
  \Drupal::state()
    ->set('entity_test_entity_create_access', TRUE);
  \Drupal::state()
    ->set('entity_test_entity_create_access_context', $context);
  if ($entity_bundle === 'forbidden_access_bundle') {

    // We need to cover a case in which a bundle is specifically forbidden
    // from creation (as opposed to neutral access).
    return AccessResult::forbidden();
  }

  // No opinion.
  return AccessResult::neutral();
}