You are here

function preview_link_test_entity_type_alter in Preview Link 8

Same name and namespace in other branches
  1. 2.x tests/modules/preview_link_test/preview_link_test.module \preview_link_test_entity_type_alter()
  2. 2.0.x tests/modules/preview_link_test/preview_link_test.module \preview_link_test_entity_type_alter()

Implements hook_entity_type_alter().

File

tests/modules/preview_link_test/preview_link_test.module, line 11
Hooks for preview_link_test.module

Code

function preview_link_test_entity_type_alter(array &$entity_types) {

  /** @var \Drupal\Core\Entity\EntityTypeInterface[] $entity_types */
  if (isset($entity_types['entity_test_revpub'])) {

    // Fixes entity_test_revpub link templates + route provider, see also
    // https://www.drupal.org/project/drupal/issues/3154413.
    $entityTestRevPub = $entity_types['entity_test_revpub'];
    $entityTestRevPub
      ->setLinkTemplate('canonical', '/entity_test_revpub/manage/{entity_test_revpub}');

    // Content moderation already set path based on the wrong canonical path,
    // override it here.
    if ($entityTestRevPub
      ->hasLinkTemplate('latest-version')) {
      $entityTestRevPub
        ->setLinkTemplate('latest-version', '/entity_test_revpub/manage/{entity_test_revpub}/latest');
    }
    $routeProviders = $entityTestRevPub
      ->getRouteProviderClasses();
    $routeProviders['html'] = Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider::class;
    $entityTestRevPub
      ->setHandlerClass('route_provider', $routeProviders);
  }
}