Change record status: 
Project: 
Introduced in branch: 
8.0.x
Introduced in version: 
8.0.0-rc1
Description: 

EntityAccessControllerInterface::access() was never properly updated to work with the D8 Entity Translation API, and still had a $langcode parameter to be used to implement per-language access control.

This parameter has been removed in favor of the entity language. For translatable entities each entity translation object will determine the language to be used for language-aware access logic.

Before:

\Drupal::entityManager()
  ->getAccessControlHandler('node')
  ->access($node, 'view', 'it');

After:

\Drupal::entityManager()
  ->getAccessControlHandler('node')
  ->access($node->getTranslation('it'), 'view');

When updating an access control handler to deal with the new API, typically the only required change is adding a $langcode = $entity->language()->getId() on top of the ::access() method body, if the $langcode parameter was used. Otherwise only the method signature needs to be updated.

The $langcode parameter of hook_entity_access() and hook_ENTITY_TYPE_access() was removed as well.

Before:

function mymodule_entity_access(EntityInterface $entity, $operation, AccountInterface $account, $langcode) {
  // do stuff...
}

After:

function mymodule_entity_access(EntityInterface $entity, $operation, AccountInterface $account) {
  $langcode = $entity->language()->getId();
  // do stuff...
}

The following methods were similarly changed:

  • EntityAccessControlHandler::checkAccess()
  • NodeGrantDatabaseStorageInterface::access()
Impacts: 
Module developers