Skip to content
Snippets Groups Projects
Commit 75f1692d authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2627852 by chx: hook_entity_create_access() is unusable

parent 829f1685
No related branches found
No related tags found
No related merge requests found
...@@ -206,6 +206,7 @@ public function resetCache() { ...@@ -206,6 +206,7 @@ public function resetCache() {
public function createAccess($entity_bundle = NULL, AccountInterface $account = NULL, array $context = array(), $return_as_object = FALSE) { public function createAccess($entity_bundle = NULL, AccountInterface $account = NULL, array $context = array(), $return_as_object = FALSE) {
$account = $this->prepareUser($account); $account = $this->prepareUser($account);
$context += array( $context += array(
'entity_type_id' => $this->entityTypeId,
'langcode' => LanguageInterface::LANGCODE_DEFAULT, 'langcode' => LanguageInterface::LANGCODE_DEFAULT,
); );
......
...@@ -592,7 +592,8 @@ function hook_ENTITY_TYPE_access(\Drupal\Core\Entity\EntityInterface $entity, $o ...@@ -592,7 +592,8 @@ function hook_ENTITY_TYPE_access(\Drupal\Core\Entity\EntityInterface $entity, $o
* The account trying to access the entity. * The account trying to access the entity.
* @param array $context * @param array $context
* An associative array of additional context values. By default it contains * 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. * - langcode - the current language code.
* @param string $entity_bundle * @param string $entity_bundle
* The entity bundle name. * The entity bundle name.
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
namespace Drupal\system\Tests\Entity; namespace Drupal\system\Tests\Entity;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Session\AccountInterface; use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Access\AccessibleInterface; use Drupal\Core\Access\AccessibleInterface;
use Drupal\Core\Entity\EntityAccessControlHandler; use Drupal\Core\Entity\EntityAccessControlHandler;
...@@ -155,6 +156,10 @@ public function testHooks() { ...@@ -155,6 +156,10 @@ public function testHooks() {
// Test hook_entity_create_access() and hook_ENTITY_TYPE_create_access(). // Test hook_entity_create_access() and hook_ENTITY_TYPE_create_access().
$entity->access('create'); $entity->access('create');
$this->assertEqual($state->get('entity_test_entity_create_access'), TRUE); $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); $this->assertEqual($state->get('entity_test_entity_test_create_access'), TRUE);
// Test hook_entity_access() and hook_ENTITY_TYPE_access(). // Test hook_entity_access() and hook_ENTITY_TYPE_access().
......
...@@ -656,6 +656,7 @@ function entity_test_entity_test_access(EntityInterface $entity, $operation, Acc ...@@ -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) { 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', TRUE);
\Drupal::state()->set('entity_test_entity_create_access_context', $context);
// No opinion. // No opinion.
return AccessResult::neutral(); return AccessResult::neutral();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment