Skip to content
Snippets Groups Projects

3200888: set 'is previewing' on entity edit form routes

All threads resolved!
1 file
+ 20
2
Compare changes
  • Side-by-side
  • Inline
@@ -6,6 +6,7 @@ use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityPublishedInterface;
use Drupal\entity_reference_preview\PreviewDetectorPluginBase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Route;
/**
* Plugin implementation of the preview_detector.
@@ -26,8 +27,9 @@ class RenderedEntityPreviewDetector extends PreviewDetectorPluginBase {
if (!$entity) {
return FALSE;
}
// This should be the same logic used to show or hide the entity tab Latest.
return $this->entityIsPreviewing($entity);
$route = $request->attributes->get('_route_object');
return $this->routeIsPreviewing($route, $entity->getEntityTypeId()) ||
$this->entityIsPreviewing($entity);
}
/**
@@ -55,6 +57,22 @@ class RenderedEntityPreviewDetector extends PreviewDetectorPluginBase {
return reset($publishable_entity_params);
}
/**
* Checks the route for "load latest revision" parameter flag.
*
* @param \Symfony\Component\Routing\Route $route
* The route for the current request.
* @param string $entity_type_id
* The ID of entity type for the route parameter.
*
* @return bool
* TRUE if the route is for a preview.
*/
private function routeIsPreviewing(Route $route, string $entity_type_id): bool {
$route_params = $route->getOption('parameters');
return $route_params[$entity_type_id]['load_latest_revision'] ?? FALSE;
}
/**
* The entity preview function.
*
Loading