function EntitySerializationTest::entityFieldAccessAlter
Same name and namespace in other branches
- main core/modules/serialization/tests/src/Kernel/EntitySerializationTest.php \Drupal\Tests\serialization\Kernel\EntitySerializationTest::entityFieldAccessAlter()
Implements hook_entity_field_access_alter().
Overrides some default access control to support testing.
Attributes
#[Hook('entity_field_access_alter')]
See also
::testUserNormalize()
File
-
core/
modules/ serialization/ tests/ src/ Kernel/ EntitySerializationTest.php, line 214
Class
- EntitySerializationTest
- Tests that entities can be serialized to supported core formats.
Namespace
Drupal\Tests\serialization\KernelCode
public function entityFieldAccessAlter(array &$grants, array $context) : void {
// Override default access control from UserAccessControlHandler to allow
// access to 'pass' field for the test user.
if ($context['field_definition']->getName() == 'pass' && $context['account']->getAccountName() == 'serialization_test_user') {
$grants[':default'] = AccessResult::allowed()->inheritCacheability($grants[':default'])
->addCacheableDependency($context['items']->getEntity());
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.