function ContentModerationRouteSubscriber::setLatestRevisionFlag

Same name in other branches
  1. 8.9.x 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()
  3. 11.x 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.
    [
        $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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.