function language_entity_field_access

language_entity_field_access($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL)

Implements hook_entity_field_access()

File

core/modules/language/language.module, line 431
Add language handling functionality to Drupal.

Code

function language_entity_field_access($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL) {
  // Only allow edit access on a langcode field if the entity it is attached to
  // is configured to have an alterable language. Also without items we can not
  // decide whether or not to allow access.
  if ($items && $operation == 'edit') {
    // Check if we are dealing with a langcode field.
    $langcode_key = $items->getEntity()->getEntityType()->getKey('langcode');
    if ($field_definition->getName() == $langcode_key) {
      // Grant access depending on whether the entity language can be altered.
      $entity = $items->getEntity();
      $config = ContentLanguageSettings::loadByEntityTypeBundle($entity->getEntityTypeId(), $entity->bundle());
      return AccessResult::forbiddenIf(!$config->isLanguageAlterable());
    }
  }
  return AccessResult::neutral();
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!modules!language!language.module/function/language_entity_field_access/8.1.x