compareNodeRevisions ignore parameters

Created on 7 September 2023, over 1 year 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);
  public function compareNodeRevisions(NodeInterface $node, $left_revision, $right_revision, $filter) {
    $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;
  }

I'll probably make a patch.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

๐Ÿ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

๐Ÿ‡จ๐Ÿ‡ฆCanada phjou Vancouver ๐Ÿ‡จ๐Ÿ‡ฆ ๐Ÿ‡ช๐Ÿ‡บ

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024