Problem/Motivation

Wrong bundle detection for nodes and taxonomy terms in TourHelper.

I found this while investigating #3553841: Routes evaluation is wrong if more than one route is given with the same name. See the MR for details. It's self-explaining.

Steps to reproduce

Check the returned 'bundle' value from loadTourEntities() and see that an ID is returned, where a bundle name is expected for nodes and taxonomy terms.

Proposed resolution

Fix the code, probably was just an oversight

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork tour-3554030

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

anybody created an issue. See original summary.

anybody’s picture

Issue summary: View changes

anybody’s picture

Status: Active » Needs review
anybody’s picture

I added some lines of documentation to better explain what it does. That would have already helped in the past to better understand what it's meant for. I'm at least pretty sure that assigning an ID to the "bundle" key here is wrong, also comparing that to the other lines where it's done correctly.

The hard-coded $route_match->getParameter('node')) also looks a bit risky to me, for example for other entity cases with "bundle" parameter, but that's a different story and I'm not totally sure about the consequences.

case 'bundle':
  case 'node_type':
    if (($entity = $route_match->getParameter('node')) && ($entity instanceof EntityInterface)) {
      if ($entity->bundle() === $tour_param) {
        $params['bundle'] = $entity->bundle();
      }
    }
    break;

Should maybe be checked in a separate issue.

smustgrave’s picture

Category: Bug report » Task
Status: Needs review » Needs work

Title and MR don't line up exactly.

anybody’s picture

Title: Wrong bundle detection for nodes and taxonomy terms in TourHelper » "bundle" route parameter is filled with entity id instead of bundle for node and taxonomy_term
Status: Needs work » Needs review

Thanks @smustgrave - hope I got you right?

anybody’s picture

Title: "bundle" route parameter is filled with entity id instead of bundle for node and taxonomy_term » Comparable "bundle" route parameter is filled with entity id instead of bundle for node and taxonomy_term
anybody’s picture

What do you think about #5 looking at the code?

grevil’s picture

Status: Needs review » Needs work
grevil’s picture

Status: Needs work » Needs review

Ok, that should be it.

anybody’s picture

@grevil sorry that was wrong, please undo and review.

grevil’s picture

Status: Needs review » Reviewed & tested by the community

Right, reverted again.

LGTM then!

smustgrave’s picture

Something we should add test coverage for?

anybody’s picture

Status: Reviewed & tested by the community » Needs work

Mhm yes I think that would make sense and shouldn't be too hard to add a test for :bundle against node or taxonomy term.
@grevil can you do that? Should fail without the fix, as it returns the ID instead of the bundle. Should you have any questions, contact me.

grevil’s picture

Title: Comparable "bundle" route parameter is filled with entity id instead of bundle for node and taxonomy_term » Wrong comparable paremter "bundle" is used for taxonomy_term / node ids.
grevil’s picture

Status: Needs work » Needs review

Ok, that should be it. The approach wasn't correct. Sorry for the gitlab noise.

grevil’s picture

Ok, I really don't get this whole switch case, or maybe I am missing something.

In line 110 we are already assigning the route parameters to the params:

// Massage the route parameters using the tour route parameters.
$params = $route_parameters;

Meaning, for the added test here, we already have "taxonomy_term: 1" now additionally we add in the switch case 'bundle' = 1 or now with the fix 'id' = 1. Both is unnecessary, since $tour->hasMatchingRoute will only check on "taxonomy_term: 1" the other added array values are completely ignored. That's why both tests succeed here, with and without the TourHelper adjustment. We could delete the WHOLE switch case and the test would still succeed, since the $params = $route_parameters before the switch case is enough, for this case to work.

Still changing the status to "Needs review" as at least it now fixes the incorrect "bundle= 1" addition.

anybody’s picture

Status: Needs review » Reviewed & tested by the community

Thanks @grevil for implementing the fix and fixing the logical issue. I agree that it seems that at least that condition is never used and that might be the reason why the bug with the wrong key here has never been experienced in the past - it's just dead (wrong) code?

Still I think the switch-case is still needed to add further parameters for comparison. But as #3554749: "bundle" route parameter only supports node shows, it has several flaws. I think our job is done here and now we at least have some more useful tests and improved code :)

liam morland’s picture

Title: Wrong comparable paremter "bundle" is used for taxonomy_term / node ids. » Wrong comparable parameter "bundle" is used for taxonomy_term / node ids.

smustgrave’s picture

Status: Reviewed & tested by the community » Needs work

Test-only run is passing when I would expect a failure.

anybody’s picture

@smustgrave I agree but as written in #20 maybe these lines are dead code? Do you have a (real world) example for this?

At least it's untested, otherwise it would have been broken!

smustgrave’s picture

Status: Needs work » Fixed

Sorry for the delays thanks for clarity. Cleaned up the pipeline some

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • smustgrave committed 13f52c18 on 2.0.x authored by anybody
    Issue #3554030: Wrong bundle detection for nodes and taxonomy terms in...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.