3 namespace Drupal\content_moderation;
5 use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
6 use Drupal\Core\Routing\RouteMatchInterface;
7 use Drupal\node\Entity\Node;
8 use Symfony\Component\DependencyInjection\ContainerInterface;
11 * Determines whether a route is the "Latest version" tab of a node.
13 class ContentPreprocess implements ContainerInjectionInterface {
16 * The route match service.
18 * @var \Drupal\Core\Routing\RouteMatchInterface $routeMatch
20 protected $routeMatch;
25 * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
26 * Current route match service.
28 public function __construct(RouteMatchInterface $route_match) {
29 $this->routeMatch = $route_match;
35 public static function create(ContainerInterface $container) {
37 $container->get('current_route_match')
42 * Wrapper for hook_preprocess_HOOK().
44 * @param array $variables
45 * Theme variables to preprocess.
47 public function preprocessNode(array &$variables) {
48 // Set the 'page' template variable when the node is being displayed on the
49 // "Latest version" tab provided by content_moderation.
50 $variables['page'] = $variables['page'] || $this->isLatestVersionPage($variables['node']);
54 * Checks whether a route is the "Latest version" tab of a node.
56 * @param \Drupal\node\Entity\Node $node
60 * True if the current route is the latest version tab of the given node.
62 public function isLatestVersionPage(Node $node) {
63 return $this->routeMatch->getRouteName() == 'entity.node.latest_version'
64 && ($pageNode = $this->routeMatch->getParameter('node'))
65 && $pageNode->id() == $node->id();