No Code Attached Yet
avatar regularlabs
regularlabs
17 Oct 2023

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?

avatar regularlabs regularlabs - open - 17 Oct 2023
avatar joomla-cms-bot joomla-cms-bot - change - 17 Oct 2023
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 17 Oct 2023
avatar Fedik
Fedik - comment - 17 Oct 2023

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

protected function onSetModules(array $value): array

However, we can add extra argument to PrepareModuleListEvent class, that will flag if array is initialised or not.
In theory

avatar Fedik Fedik - change - 17 Oct 2023
Title
Incorrect initial value of $modules for onPrepareModuleList event
[5.0] Incorrect initial value of $modules for onPrepareModuleList event
avatar Fedik Fedik - edited - 17 Oct 2023
avatar bembelimen
bembelimen - comment - 17 Oct 2023

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?

avatar regularlabs
regularlabs - comment - 17 Oct 2023

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...

avatar Fedik
Fedik - comment - 17 Oct 2023

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

avatar Fedik Fedik - change - 22 Oct 2023
Status New Closed
Closed_Date 0000-00-00 00:00:00 2023-10-22 10:06:18
Closed_By Fedik
avatar Fedik Fedik - close - 22 Oct 2023
avatar Fedik
Fedik - comment - 22 Oct 2023

Please review and test #42197

avatar regularlabs
regularlabs - comment - 23 Oct 2023

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.

avatar ssnobben
ssnobben - comment - 13 Nov 2023

So what did this go to?

avatar alikon alikon - change - 13 Nov 2023
Status Closed New
Closed_Date 2023-10-22 10:06:18
Closed_By Fedik
avatar alikon alikon - reopen - 13 Nov 2023
avatar alikon
alikon - comment - 13 Nov 2023

the pr #42197 has been closed, so reopening this issue

avatar Fedik
Fedik - comment - 13 Nov 2023

There no reason to keep this open, the $modules will stay as array.

avatar alikon alikon - change - 13 Nov 2023
Status New Closed
Closed_Date 0000-00-00 00:00:00 2023-11-13 18:57:52
Closed_By alikon
avatar alikon alikon - close - 13 Nov 2023
avatar alikon
alikon - comment - 13 Nov 2023

ok

avatar regularlabs
regularlabs - comment - 13 Nov 2023

@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).

avatar Fedik
Fedik - comment - 13 Nov 2023

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.

avatar regularlabs
regularlabs - comment - 15 Nov 2023

Here is another message you can mark as abusive without reason.
A shame nothing ever changes in the way people are treated by core developers.

image

avatar ssnobben
ssnobben - comment - 15 Nov 2023

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.
The_Zachman_Framework_of_Enterprise_Architecture

Thks.

Add a Comment

Login with GitHub to post a comment