function hook_entity_field_access_alter(array &
$grants, array
$context) { /** @var \Drupal\Core\Field\FieldDefinitionInterface $field_definition */
$field_definition =
$context['field_definition'
];
if ($field_definition->
getName() == 'field_of_interest' &&
$grants['node'
]->
isForbidden()) { // Override node module's restriction to no opinion (neither allowed nor
// forbidden). We don't want to provide our own access hook, we only want to
// take out node module's part in the access handling of this field. We also
// don't want to switch node module's grant to
// AccessResultInterface::isAllowed() , because the grants of other modules
// should still decide on their own if this field is accessible or not
$grants['node'
] = AccessResult::
neutral()->
inheritCacheability($grants['node'
]);
}}/**
* Acts when initializing a fieldable entity object.
*
* This hook runs after a new entity object or a new entity translation object
* has just been instantiated. It can be used to set initial values, e.g. to
* provide defaults.
*
* @param \Drupal\Core\Entity\FieldableEntityInterface $entity
* The entity object.
*
* @ingroup entity_crud
* @see hook_ENTITY_TYPE_field_values_init()
*/