You are here

protected function ContentModerationRouteSubscriber::setLatestRevisionFlag in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/content_moderation/src/Routing/ContentModerationRouteSubscriber.php \Drupal\content_moderation\Routing\ContentModerationRouteSubscriber::setLatestRevisionFlag()
  2. 10 core/modules/content_moderation/src/Routing/ContentModerationRouteSubscriber.php \Drupal\content_moderation\Routing\ContentModerationRouteSubscriber::setLatestRevisionFlag()

Ensure revisionable entities load the latest revision on entity forms.

Parameters

\Symfony\Component\Routing\Route $route: The route object.

1 call to ContentModerationRouteSubscriber::setLatestRevisionFlag()
ContentModerationRouteSubscriber::alterRoutes in core/modules/content_moderation/src/Routing/ContentModerationRouteSubscriber.php
Alters existing routes for a specific collection.

File

core/modules/content_moderation/src/Routing/ContentModerationRouteSubscriber.php, line 63

Class

ContentModerationRouteSubscriber
Subscriber for moderated revisionable entity forms.

Namespace

Drupal\content_moderation\Routing

Code

protected function setLatestRevisionFlag(Route $route) {
  if (!($entity_form = $route
    ->getDefault('_entity_form'))) {
    return;
  }

  // Only set the flag on entity types which are revisionable.
  list($entity_type) = explode('.', $entity_form, 2);
  if (!isset($this
    ->getModeratedEntityTypes()[$entity_type]) || !$this
    ->getModeratedEntityTypes()[$entity_type]
    ->isRevisionable()) {
    return;
  }
  $parameters = $route
    ->getOption('parameters') ?: [];
  foreach ($parameters as &$parameter) {
    if (isset($parameter['type']) && $parameter['type'] === 'entity:' . $entity_type && !isset($parameter['load_latest_revision'])) {
      $parameter['load_latest_revision'] = TRUE;
    }
  }
  $route
    ->setOption('parameters', $parameters);
}