compareNodeRevisions ignore the node parameter

Created on 7 September 2023, 10 months ago
Updated 21 May 2024, about 1 month ago

Problem/Motivation

The code has a compareNodeRevisions function which takes the node as a parameter. But it is not used at all in the code, it is pulling it from the route match instead, which is making it impossible to reuse.

  public function compareNodeRevisions(NodeInterface $node, $left_revision, $right_revision, $filter) {
    $storage = $this->entityTypeManager()->getStorage('node');
    $route_match = \Drupal::routeMatch();
    $left_revision = $storage->loadRevision($left_revision);
    $right_revision = $storage->loadRevision($right_revision);
    $build = $this->compareEntityRevisions($route_match, $left_revision, $right_revision, $filter);
    return $build;
  }

Why $node is just passed without being used. Am I missing something? Shouldn't it be passed to compareEntityRevisions instead of the route_match, and then get rid of that weird code that reload the node again using the route match and the left revision. Moreover, using the route match just makes it impossible to reuse in a route that has different parameters names or even worse a cron environment.

  public function compareEntityRevisions(RouteMatchInterface $route_match, ContentEntityInterface $left_revision, ContentEntityInterface $right_revision, $filter) {
    $entity_type_id = $left_revision->getEntityTypeId();
    /** @var \Drupal\Core\Entity\EntityInterface $entity */
    $entity = $route_match->getParameter($entity_type_id);

    $entity_type_id = $entity->getEntityTypeId();
    $storage = $this->entityTypeManager()->getStorage($entity_type_id);

I'll probably make a patch.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Needs work

Version

1.0

Component

Code

Created by

🇨🇦Canada phjou Vancouver/Paris 🇨🇦 🇪🇺

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.69.0 2024