You are here

public function ScheduledTransitionsEntityHooks::entityTypeBuild in Scheduled Transitions 8

Same name and namespace in other branches
  1. 2.x src/ScheduledTransitionsEntityHooks.php \Drupal\scheduled_transitions\ScheduledTransitionsEntityHooks::entityTypeBuild()

Implements hook_entity_type_build().

See also

\scheduled_transitions_entity_type_build()

File

src/ScheduledTransitionsEntityHooks.php, line 89

Class

ScheduledTransitionsEntityHooks
Entity related hooks for Scheduled Transitions module.

Namespace

Drupal\scheduled_transitions

Code

public function entityTypeBuild(array &$entityTypes) : void {

  /** @var \Drupal\Core\Entity\EntityTypeInterface[] $entityTypes */
  foreach ($entityTypes as $entityType) {
    if (!$entityType
      ->hasLinkTemplate('canonical') || !$entityType instanceof ContentEntityType) {
      continue;
    }
    if ($entityType
      ->id() === 'scheduled_transition') {
      continue;
    }

    // Add our entity route provider.
    $routeProviders = $entityType
      ->getRouteProviderClasses() ?: [];
    $routeProviders['scheduled_transitions'] = ScheduledTransitionsRouteProvider::class;
    $entityType
      ->setHandlerClass('route_provider', $routeProviders);
    $canonicalPath = $entityType
      ->getLinkTemplate('canonical');
    $entityType
      ->setFormClass(ScheduledTransitionsRouteProvider::FORM, ScheduledTransitionForm::class)
      ->setLinkTemplate(ScheduledTransitionsRouteProvider::LINK_TEMPLATE, $canonicalPath . ScheduledTransitionsRouteProvider::CANONICAL_PATH_SUFFIX);
    $entityType
      ->setFormClass(ScheduledTransitionsRouteProvider::FORM_ADD, ScheduledTransitionAddForm::class)
      ->setLinkTemplate(ScheduledTransitionsRouteProvider::LINK_TEMPLATE_ADD, $canonicalPath . ScheduledTransitionsRouteProvider::CANONICAL_PATH_SUFFIX_ADD);
  }
}