You are here

function menu_item_role_access_entity_field_access in Menu Item Role Access 8

Same name and namespace in other branches
  1. 8.2 menu_item_role_access.module \menu_item_role_access_entity_field_access()

Implements hook_entity_field_access().

We want to make sure that fields aren't being edited by those who shouldn't.

File

./menu_item_role_access.module, line 85
Menu Item Role Access module.

Code

function menu_item_role_access_entity_field_access($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL) {
  if ($field_definition
    ->getName() == 'menu_item_roles') {
    if ($operation == 'edit' and $account
      ->hasPermission('edit menu_item_role_access')) {
      return AccessResult::allowed();
    }

    // Anything else on this field is forbidden.
    return AccessResult::forbidden();
  }
  return AccessResult::neutral();
}