A bit late to the party. But there is still a bit of an issue in the ModuleHelper::load
method (libraries/src/Helper/ModuleHelper.php
).
In Joomla 4 it initially passes the $modules
object to the onPrepareModuleList
event as null
.
This way plugins can see the difference between an unset or an empty module list.
In Joomla 5 however, it is initially set to an empty array. So plugins can no longer tell the difference.
That difference is important!
Say you have 2 plugins that do something on onPrepareModuleList
.
Plugin 1 checks stuff and decides the module list should be empty (= no modules should be rendered).
Plugin 2 sees an empty array and says: "Ok, another plugin already decided there are no modules. So we don't have to do anything.
Or:
Plugin 1 checks stuff and decides it should not do anything. So it leaves the $modules
as it is (null
)
Plugin 2 sees the null
value and says: "Ok, we are first to the party. Lets grab the modules we want to push into the $modules
list.
Again: no longer possible in Joomla 5.
So now a second plugin would have to override the empty array module list even if a previous module purposely set it that way.
So can the $modules = [];
be changed back to $modules = null;
in the ModuleHelper::load
method?
Labels |
Added:
No Code Attached Yet
|
Title |
|
This sounds like a very unreliable way of checking if modules are loaded or not.
Wouldn't it be better to communicate it by either asking the other plugin, storing the info somewhere or as Fedir suggested by adding more arguments?
I'm just stating how it was done pre-Joomla5.
With Joomla 5 the behaviour has changed. So a breaking change.
And for now, no way to see if the $modules array is empty because it is purposely made empty, or it hasn't been looked at yet.
I take it that any change to this will have to wait till J6 (and will probably be done completely different then).
So I'll just have to override the empty $modules array in the Joomla 5 version of my plugin. Which can cause conflicts with other plugins. Oh well...
Adding a new argument should be an easy thing. Then plugin can use kind of:
if (!$event->getModuleListInitialised()) {
$event->updateModules($myModulesArray);
$event->setModuleListInitialised(true);
}
this will have to wait till J6
It can be done for 5.0.x as bug fix if maintainer will agree. or in 5.1
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2023-10-22 10:06:18 |
Closed_By | ⇒ | Fedik |
This sounds like a very unreliable way of checking if modules are loaded or not.
Actually, as @Fedik noticed in the core code (seeing there is a fix there too in the PR), Joomla uses this method itself to see if any modules have purposely set the modules array to an empty array or if it is still false.
// If the onPrepareModuleList event returns an array of modules, then ignore the default module list creation
if (!$modules) {
$modules = static::getModuleList();
}
So setting the $modules to the empty array to begin with, breaks that core code in the same method.
So yeah, the added setLoaded
in #42197 is a different way to solve it.
But it completely changes the way this now works.
So in other words, the $modules = [];
is not just a BC break, but also a bug.
And adding a setLoaded
is a new feature and is not a fix for the bug.
So what did this go to?
Status | Closed | ⇒ | New |
Closed_Date | 2023-10-22 10:06:18 | ⇒ | |
Closed_By | Fedik | ⇒ |
There no reason to keep this open, the $modules
will stay as array.
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2023-11-13 18:57:52 |
Closed_By | ⇒ | alikon |
ok
@Fedik Ok, so you are saying you are keeping the initial $modules
as an empty array (and noot null
), forcefully creating a BC break. Ok, clear. I'll hack my way around things again.
Another case of changes for changes sake, without accounting for how things are used by extensions (the life-blood of Joomla).
The event purpuse is to allow to initialise the modules list outside, by extensions. Look original PR #6320
If you need to filter/add/remove modules, then there 2 more events for that:
onAfterModuleList
onAfterCleanModuleList
Another case of changes for changes sake
It is for data consistency.
Please core devs and team make a positive open environment for all contributing people on all levels that are not coding the Joomla core but important involved with the project long term.
With all discussed and important changes its good to make all people understand similar arguments analysis like the Zachman framework analysis: why, how, what, who, where, when to get answered in a polite manner.
Thks.
It is late to do such change at this point.
It was made to keep data consistent, to be sure it is always an array
joomla-cms/libraries/src/Event/Module/ModuleListEvent.php
Line 73 in d38a8ff
However, we can add extra argument to
PrepareModuleListEvent
class, that will flag if array is initialised or not.In theory