You are here

function taxonomy_access_fix_entity_type_alter in Taxonomy access fix 8.3

Same name and namespace in other branches
  1. 8 taxonomy_access_fix.module \taxonomy_access_fix_entity_type_alter()
  2. 8.2 taxonomy_access_fix.module \taxonomy_access_fix_entity_type_alter()

Implements hook_entity_type_alter().

File

./taxonomy_access_fix.module, line 18
Hook implementations by Taxonomy Access Fix module.

Code

function taxonomy_access_fix_entity_type_alter(array &$entity_types) {
  $entity_types['taxonomy_vocabulary']
    ->setHandlerClass('list_builder', 'Drupal\\taxonomy_access_fix\\VocabularyListBuilder');
  $access_handler_class = $entity_types['taxonomy_vocabulary']
    ->getHandlerClass('access');
  if ($access_handler_class !== OriginalVocabularyAccessControlHandler::class) {

    // If an unexpected access control handler is in use, we can't guarantee
    // that our replacement handler will return correct access results.
    throw new LogicException('Unexpected access handler implementation in use for Taxonomy vocabulary entities. This might be due to an unexpected change in Drupal Core or due to a conflict with another contributed or custom module in use.');
  }
  $entity_types['taxonomy_vocabulary']
    ->setHandlerClass('access', VocabularyAccessControlHandler::class);
  $access_handler_class = $entity_types['taxonomy_term']
    ->getHandlerClass('access');
  if ($access_handler_class !== OriginalTermAccessControlHandler::class) {

    // If an unexpected access control handler is in use, we can't guarantee
    // that our replacement handler will return correct access results.
    throw new LogicException('Unexpected access handler implementation in use for Taxonomy term entities. This might be due to an unexpected change in Drupal Core or due to a conflict with another contributed or custom module in use.');
  }
  $entity_types['taxonomy_term']
    ->setHandlerClass('access', TermAccessControlHandler::class);
}