joomla-cms icon indicating copy to clipboard operation
joomla-cms copied to clipboard

[6.0] Fix tagged items URLs for items with the same view

Open AlterBrains opened this issue 1 year ago • 37 comments

Summary of Changes

"Tags > List of tagged items" view uses Joomla\Component\Tags\Site\Helper\RouteHelper::getItemRoute() to get a URL of individual item.

It uses Joomla\CMS\Helper\RouteHelper::getRoute(), if no JPATH_BASE . '/components/' . $explodedAlias[0] . '/helpers/route.php' is found.

Assuming that we have modern components with Router service, the tagged item URL is generated via Joomla\CMS\Helper\RouteHelper::getRoute().

This method adds the Itemid via this code:

        if ($item = $this->findItem($needles)) {
            $link .= '&Itemid=' . $item;
        }

The problem is that the new routers are using the NoMenuRule and can auto-find the correct Itemid themselves.

Hence, there is no need to auto-find the Itemid here.

Another problem is that Joomla\CMS\Helper\RouteHelper::findItem() uses internal static cache of needles per view name.

Hence, if we have multiple components with the same view name, the second component will receive invalid Itemid because its URL generation will use the needles cache of the first component with the same view name.

Testing Instructions

Create multiple tagged items from different component but with the same view name.

Actual result BEFORE applying this Pull Request

See broken URLs if you browser the list of tagged items where we have the items from different components but the same view.

Expected result AFTER applying this Pull Request

Correct URLs respecting the components' specific Itemids.

Link to documentations

Please select:

  • [ ] Documentation link for docs.joomla.org:

  • [x] No documentation changes for docs.joomla.org needed

  • [ ] Pull Request link for manual.joomla.org:

  • [x] No documentation changes for manual.joomla.org needed

AlterBrains avatar Apr 26 '24 19:04 AlterBrains

I reviewed your change and it indeed fixes the issue. A good catch. However, I see 2 theoretical issues:

  1. What if someone extends from this class? Since $lookup is not private, they could access this and this change could break that.
  2. Coincidentally, the class is inherited by a RouteHelper class in com_tags, but that class overwrites the original lookup and it is also dead code at this point.

I would consider the risk for this to break anything minimal, but if we want to be nitpicking here, this would be a b/c break. For me, it is a weighing between fixing the bug and introducing a minor b/c break.

Hackwar avatar Jul 05 '24 12:07 Hackwar

What if someone extends from this class? Since $lookup is not private, they could access this and this change could break that.

Lots of Joomla classes can be extended and break smth. It's not a problem. We have an open source "easily extendable" project, I am sure that is should not contain the words "private" or "final" at all. Otherwise, it looks like commercial code. And making $lookup private will break extensions which can potentially inherit from class.

Coincidentally, the class is inherited by a RouteHelper class in com_tags, but that class overwrites the original lookup and it is also dead code at this point.

I don't see any overrides in TagsHelperRoute.

I would consider the risk for this to break anything minimal, but if we want to be nitpicking here, this would be a b/c break. For me, it is a weighing between fixing the bug and introducing a minor b/c break.

To be honest, I don't see any b/c breaks, it's just a bug fix. The people are waiting for this bug to be fixed since Apr.

AlterBrains avatar Jul 06 '24 07:07 AlterBrains

Create multiple tagged items from different component but with the same view name.

@AlterBrains can you give an example what exactly to test?

ghost avatar Aug 16 '24 09:08 ghost

You need two components, each with items which can be tagged using native Joomla tags, and items should have the same "view" name in request. A test requires custom component with article view. Unfortunately, we don't have such extension.

AlterBrains avatar Aug 16 '24 10:08 AlterBrains

@AlterBrains thanks for the answer. I don't understand it, no test.

ghost avatar Aug 16 '24 10:08 ghost

This pull request has been automatically rebased to 5.2-dev.

HLeithner avatar Sep 02 '24 08:09 HLeithner

I have tested this item :white_check_mark: successfully on 53d3d3c4812b392205a1bc1454ec2be6ded5477c


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/43379.

Denitz avatar Nov 28 '24 05:11 Denitz

I have tested this item :white_check_mark: successfully on 53d3d3c4812b392205a1bc1454ec2be6ded5477c

I've also tested it succesfully.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/43379.

Majoroff avatar Nov 28 '24 09:11 Majoroff

I have tested this item :white_check_mark: successfully on 53d3d3c4812b392205a1bc1454ec2be6ded5477c


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/43379.

globalJavert avatar Dec 09 '24 09:12 globalJavert

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/43379.

richard67 avatar Dec 09 '24 18:12 richard67

I fear that this change can lead to some implications for extension developers when they are using this class as the lookup array is now built differently. Is it possible to make it in a more backwards compatible way?

laoneo avatar Dec 13 '24 07:12 laoneo

@laoneo I don't see any other way. We change the structure of protected RouteHelper::$lookup array which is only accessed directly by RouteHelper, the output of all other RouteHelper methods stays same and there are no changes for all extensions which use RouteHelper methods.

Don't think that there are any implications. Only if a developer extends RouteHelper and applies custom access to $lookup but I doubt that we have cases. Or at least they are absolutely rare.

AlterBrains avatar Dec 13 '24 11:12 AlterBrains

It's a protected variable, so very likely that it gets used by extending classes in 3rd party extensions. The problem is that this break can't be used in extensions which for example have compatibility to J4.

What about having the normal lookup and when that one fails, use the one with the extension parameter? At least that's how I would do it.

laoneo avatar Dec 13 '24 12:12 laoneo

The problem is, that it doesn't fail. If you have 2 components which have the view "category" and use their own category implementation, they (can) collide here and you have a hit in the lookup for category X, but it is actually the category X of component B instead of component A.

Hackwar avatar Dec 13 '24 12:12 Hackwar

Difficult then, but yeah I see your point.

laoneo avatar Dec 13 '24 12:12 laoneo

@Hackwar Hm.. but RouteHelper::getCategoryRoute() requires $extension argument, we can use it!

I can update patch and add optional $extension argument for lookupItem(), it will be used in call from getCategoryRoute(). lookupItem() will fill $extension for new RouterHelper instance and it won't use request via:

        if ($this->extension === null) {
            $this->extension = $app->getInput()->getCmd('option');
        }

Hence, RouterHelper::getCategoryRoute() will always use the correct $extension.

Agree?

AlterBrains avatar Dec 13 '24 12:12 AlterBrains

The problem isn't the input to the methods, but the lookup table itself. The attribute is protected, but not private, so a class extending from this class could try to read $lookup and fail because the structure is wrong.

Hackwar avatar Dec 13 '24 12:12 Hackwar

Ready. Anyway, it's a bug. I believe 3rd-party classes should adopt to bug fixes in the core, but it's not the core who adopts to unknown classes :(

AlterBrains avatar Dec 13 '24 13:12 AlterBrains

We are still discussing this.

Hackwar avatar Dec 13 '24 13:12 Hackwar

Please fix the codestyle.

Hackwar avatar Dec 13 '24 13:12 Hackwar

@Hackwar Fixed, thanks for reporting!

AlterBrains avatar Dec 13 '24 14:12 AlterBrains

I have tested this item :white_check_mark: successfully on b40f9ed11e8c780e6b5641ef8d103a0166658fbb


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/43379.

Majoroff avatar Dec 18 '24 10:12 Majoroff

I have tested this item :white_check_mark: successfully on 5e0256a34cf04b85859c4249f089e07d074084b3

Will it ever be solved?


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/43379.

Majoroff avatar Mar 21 '25 11:03 Majoroff

Will it ever be solved?

@Majoroff Needs as always a second successfull test for a next step.

ghost avatar Mar 21 '25 12:03 ghost

I have tested this item :white_check_mark: successfully on 5e0256a34cf04b85859c4249f089e07d074084b3


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/43379.

globalJavert avatar Mar 21 '25 12:03 globalJavert

We are still discussing this.

@Hackwar Any news about that?

richard67 avatar Mar 21 '25 14:03 richard67

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/43379.

richard67 avatar Mar 21 '25 14:03 richard67

Just merge it. It can't get worse than it is already...

Hackwar avatar Mar 22 '25 08:03 Hackwar

This pull request has been automatically rebased to 5.3-dev.

HLeithner avatar Apr 15 '25 16:04 HLeithner

@laoneo All done.

AlterBrains avatar Apr 17 '25 08:04 AlterBrains