User tests: Successful: Unsuccessful:
We allow to modify the router by adding rules to it. So far often enough this was done by using a plugin and adding those rules on onAfterInitialise. This however poses a problem when we are not in the SiteApplication and want to create a link, since the router might not be instantiated properly. Often enough plugins are checking if the current application is the SiteApplication, and if not, they don't react. However that means when you are in the backend and create a link to the frontend for for example a mailing, the URL might be wrong, because the plugins with the custom behavior didn't attach that behavior to the router, since it thought it was in the wrong context.
This PR introduces the new onAfterInitialiseRouter
event. This event is triggered each time the router object is created (which should only be once per process) and allows plugins to add their logic independent of the currently running application and especially independent of when the object is created. To show how this would be used in the future, the languagefilter plugin has been changed to use this new method.
I first was sure that the languagefilter plugin would suffer from the problem I described above and that this would be a hidden bug. However I then noticed that the plugin "gets around this", by forcing the SiteRouter object upon plugin instantiation. I consider this pretty bad style...
Setup a multi language site and apply the patch. Notice that the URLs/behavior did not change.
Please select:
Documentation link for docs.joomla.org:
No documentation changes for docs.joomla.org needed
Pull Request link for manual.joomla.org:
No documentation changes for manual.joomla.org needed
Status | New | ⇒ | Pending |
Category | ⇒ | Libraries Front End Plugins |
Labels |
Added:
PR-5.1-dev
|
Labels |
Added:
Feature
|
Visiting a home page, got an error:
SiteRouter not set in Joomla\Plugin\System\LanguageFilter\Extension\LanguageFilter
from
I have tested this item ✅ successfully on 222e9ae
Works now.
Vielen Dank!
I see, but you already set the router at
So you probably can revert $this->getApplication()->getRouter()
back to $this->getSiteRouter()
, because this code runs only for site
application, or?
I'm not happy that we have the get/setSiteRouter at all and I don't like the order in which this is set. I would either keep it the way it is with the getApplication()->getRouter() or get it directly from the DI container. But someone decided that we should deprecate the getRouter() and at the same time it is frowned upon to get this from the container directly. But the get/setSiteRouter also is nasty. Why do we have this for one specific application router? Why shouldn't we have this for all applications? And with this being called when the plugin is instantiated, the router is created before the system plugins are loaded, thus making it impossible to run a system plugin on the onAfterRouterInitialise event. It basically is just a matter of time when a third party extension uses this code and thus breaks this feature.
You should not need an application to get the router from it. As only the SiteRouter is needed to create different urls, I decided to create that one first, if over time we need some other ones for more applications, then feel free to create new services.
I have tested this item ✅ successfully on 222e9ae
Fine for me. Did a core review and also tested the functionality of the new event in the depending PRs.
Status | Pending | ⇒ | Ready to Commit |
RTC
Labels |
Added:
RTC
|
Category | Libraries Front End Plugins | ⇒ | Administration com_config Language & Strings Libraries Front End Plugins |
In the maintainer meeting we discussed this PR and agreed on adding a notice to the global configuration that there are additional settings in the SEF system plugin. This has been added to this PR now.
@Fedik @SniperSister would you be able to test this again?
I have tested this item ? unsuccessfully on 07c4e6a
Labels |
Added:
Language Change
|
Has been fixed.
I would agree with you, however the global configuration code doesn't allow that. I'm going to revert the whole notice part and this apparently will have to go into an additional PR.
Category | Libraries Front End Plugins Administration com_config Language & Strings | ⇒ | Libraries Front End Plugins |
Status | Ready to Commit | ⇒ | Pending |
I have tested this item ✅ successfully on eafa7fa
I have tested this item ✅ successfully on eafa7fa
I've re-tested the PR after the latest changes, works as described.
Status | Pending | ⇒ | Ready to Commit |
RTC
Labels |
Removed:
Language Change
|
Status | Ready to Commit | ⇒ | Fixed in Code Base |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2024-02-25 06:40:16 |
Closed_By | ⇒ | LadySolveig |
Thank you @Hackwar and also for testing and review @Fedik @laoneo @SniperSister @wilsonge @brianteeman
Looks good. Only a couple notes.
Can we please place it here:
joomla-cms/libraries/src/Service/Provider/Router.php
Lines 42 to 50 in e2170c8
kind of:
This way it will be more modular, and consistent when at some point we decide to extend it to another Routers.
And keep __constructor clean.
Another note. As @wilsonge already wrote.
Please remove
PluginHelper::importPlugin
it should be already imported outside (actualy it already done in App initialisation), if it not then it not a Router problem.