diff --git a/core/includes/entity.api.php b/core/includes/entity.api.php index 5295bbb..a7fdfcb 100644 --- a/core/includes/entity.api.php +++ b/core/includes/entity.api.php @@ -528,7 +528,7 @@ function hook_entity_field_info_alter(&$info, $entity_type) { * The user account to check. * * @return bool|NULL - * TRUE if access hould be allowed, FALSE if access should be denied and NULL + * TRUE if access should be allowed, FALSE if access should be denied and NULL * if the implementation has no opinion. */ function hook_entity_field_access($operation, $field, $account) { diff --git a/core/lib/Drupal/Core/Entity/Field/Type/Field.php b/core/lib/Drupal/Core/Entity/Field/Type/Field.php index be40ec1..305fc1f 100644 --- a/core/lib/Drupal/Core/Entity/Field/Type/Field.php +++ b/core/lib/Drupal/Core/Entity/Field/Type/Field.php @@ -158,7 +158,8 @@ public function access($operation = 'view', User $account = NULL) { // Invoke hook and collect grants/denies for field access from other // modules. Our default access flag is masked under the ':default' key. $grants = array(':default' => $access); - foreach (module_implements('entity_field_access') as $module) { + $hook_implementations = drupal_container()->get('module_handler')->getImplementations('entity_field_access'); + foreach ($hook_implementations as $module) { $grants = array_merge($grants, array($module => module_invoke($module, 'entity_field_access', $operation, $this, $account))); } // Also allow modules to alter the returned grants/denies. diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/FieldAccessTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/FieldAccessTest.php index 7945b7c..09e7a7a 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/FieldAccessTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/FieldAccessTest.php @@ -43,20 +43,10 @@ protected function setUp() { parent::setUp(); // Install field module schema. $this->installSchema('field', array('field_config', 'field_config_instance')); + // The users table is needed for creating dummy user accounts. + $this->installSchema('user', array('users')); // Register entity_test text field. entity_test_install(); - // The global user account refers to the user that initiated this test run. - // Mask the global user as anonymous to avoid any user account loading. - global $user; - $this->activeUid = $user->uid; - $user->uid = 0; - } - - protected function tearDown() { - // Restore the original global user ID. - global $user; - $user->uid = $this->activeUid; - parent::tearDown(); } /** @@ -75,12 +65,17 @@ function testFieldAccess() { ), ); $entity = entity_create('entity_test', $values); - $this->assertFalse($entity->field_test_text->access('view'), 'Access to the field was denied.'); + + // Create a dummy user account for testing access with. + $values = array('name' => 'test'); + $account = entity_create('user', $values); + + $this->assertFalse($entity->field_test_text->access('view', $account), 'Access to the field was denied.'); $entity->field_test_text = 'access alter value'; - $this->assertFalse($entity->field_test_text->access('view'), 'Access to the field was denied.'); + $this->assertFalse($entity->field_test_text->access('view', $account), 'Access to the field was denied.'); $entity->field_test_text = 'standard value'; - $this->assertTrue($entity->field_test_text->access('view'), 'Access to the field was granted.'); + $this->assertTrue($entity->field_test_text->access('view', $account), 'Access to the field was granted.'); } }