You are here

function twig_field_entity_field_access in Twig Field 8

Implements hook_entity_field_access().

File

./twig_field.module, line 43
Primary module hooks for Twig field module.

Code

function twig_field_entity_field_access($operation, FieldDefinitionInterface $field_definition, AccountInterface $account) {
  if ($operation == 'edit' && $field_definition
    ->getType() == 'twig') {
    return AccessResult::forbiddenIf(!$account
      ->hasPermission('access twig fields'))
      ->addCacheContexts([
      'user.permissions',
    ]);
  }
  return AccessResult::neutral();
}