diff --git a/core/lib/Drupal/Core/Entity/EntityAccessControlHandler.php b/core/lib/Drupal/Core/Entity/EntityAccessControlHandler.php index 6d8d7fb3b7520fe49bbc58c4aebd637451a650a8..27fda29eb1c06e7258e021a5ab6f156291b65d46 100644 --- a/core/lib/Drupal/Core/Entity/EntityAccessControlHandler.php +++ b/core/lib/Drupal/Core/Entity/EntityAccessControlHandler.php @@ -206,6 +206,7 @@ public function resetCache() { public function createAccess($entity_bundle = NULL, AccountInterface $account = NULL, array $context = array(), $return_as_object = FALSE) { $account = $this->prepareUser($account); $context += array( + 'entity_type_id' => $this->entityTypeId, 'langcode' => LanguageInterface::LANGCODE_DEFAULT, ); diff --git a/core/lib/Drupal/Core/Entity/entity.api.php b/core/lib/Drupal/Core/Entity/entity.api.php index be2a9038417d0bbfbe7766e8cc66aa95798bfc87..d33b422be4571dd75eedce3a1240fa61b41f5fef 100644 --- a/core/lib/Drupal/Core/Entity/entity.api.php +++ b/core/lib/Drupal/Core/Entity/entity.api.php @@ -592,7 +592,8 @@ function hook_ENTITY_TYPE_access(\Drupal\Core\Entity\EntityInterface $entity, $o * The account trying to access the entity. * @param array $context * An associative array of additional context values. By default it contains - * language: + * language and the entity type ID: + * - entity_type_id - the entity type ID. * - langcode - the current language code. * @param string $entity_bundle * The entity bundle name. diff --git a/core/modules/system/src/Tests/Entity/EntityAccessControlHandlerTest.php b/core/modules/system/src/Tests/Entity/EntityAccessControlHandlerTest.php index ab73ee12ad327174a6e19cae4b8f88112dc99103..38334766ab7a204126c5edb093545acc8676f5ac 100644 --- a/core/modules/system/src/Tests/Entity/EntityAccessControlHandlerTest.php +++ b/core/modules/system/src/Tests/Entity/EntityAccessControlHandlerTest.php @@ -7,6 +7,7 @@ namespace Drupal\system\Tests\Entity; +use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Session\AccountInterface; use Drupal\Core\Access\AccessibleInterface; use Drupal\Core\Entity\EntityAccessControlHandler; @@ -155,6 +156,10 @@ public function testHooks() { // Test hook_entity_create_access() and hook_ENTITY_TYPE_create_access(). $entity->access('create'); $this->assertEqual($state->get('entity_test_entity_create_access'), TRUE); + $this->assertIdentical($state->get('entity_test_entity_create_access_context'), [ + 'entity_type_id' => 'entity_test', + 'langcode' => LanguageInterface::LANGCODE_DEFAULT, + ]); $this->assertEqual($state->get('entity_test_entity_test_create_access'), TRUE); // Test hook_entity_access() and hook_ENTITY_TYPE_access(). diff --git a/core/modules/system/tests/modules/entity_test/entity_test.module b/core/modules/system/tests/modules/entity_test/entity_test.module index e172576f69086222953b79f6ae721e98207acd29..59e44b6992b501b12bb00dbf3e292f10426d355c 100644 --- a/core/modules/system/tests/modules/entity_test/entity_test.module +++ b/core/modules/system/tests/modules/entity_test/entity_test.module @@ -656,6 +656,7 @@ function entity_test_entity_test_access(EntityInterface $entity, $operation, Acc */ 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); // No opinion. return AccessResult::neutral();