Joomla-cms: [4.0] Plugin as services side effect - B/C break

Created on 15 May 2019  路  14Comments  路  Source: joomla/joomla-cms

Steps to reproduce the issue

@laoneo after your PR https://github.com/joomla/joomla-cms/pull/20547
the execution of plugins has changed based on the constructor return value.

Till now if a plugin __construct returned 'false' the plugin execution was completely stopped and all attached event listeners skipped

With the plugin as service dispatching this doesn't happen anymore, a plugin is always executed and all attached event listeners through getSubscribedEvents are always called despite the fact that the __construct of the plugin is returning false.

So, what we do? What is the supposed method to stop programmatically the execution of a plugin?

Pinging @wilsonge and @laoneo author of this system

Documentation Required J4 Issue No Code Attached Yet

Most helpful comment

I've discussed this with Production and we have agreed that rather than fixing this we will not support this behaviour in Joomla 4. I have documented this in the plugin section on the b/c breaks page here https://docs.joomla.org/Potential_backward_compatibility_issues_in_Joomla_4#Plugins

As a result I'm closing this issue

All 14 comments

More specifically it seems that this happens because you move the registerListeners() out of the CMSPlugin __construct to the PluginHelper class

Till now if a plugin __construct returned 'false' the plugin execution was completely stopped

Don't think so that this existed till now like that, and if then it was wrong as the constructor should not return any value. It just didn't register when the parent constructor is not called.

What is the supposed method to stop programmatically the execution of a plugin?

You mean within a plugin? Just overwrite the registerListeners function as you can do already and should do.

Yes, more than the return value of the constructor itself to not register a plugin it was needed to return before the parent constructor is called.

Yes, now the only way is overwrite the registerListeners function.

Could we find something better than overwriting a parent method? It's not so beautiful

You should overwrite the function also the old way. Not calling a parent constructor should be avoided. Because then you have no guarantee that when something got changed in the base class is also working in your extending one.

Increasing priority as per guidelines for beta-blockers.


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

I've discussed this with Production and we have agreed that rather than fixing this we will not support this behaviour in Joomla 4. I have documented this in the plugin section on the b/c breaks page here https://docs.joomla.org/Potential_backward_compatibility_issues_in_Joomla_4#Plugins

As a result I'm closing this issue

Please give a solution for this. It will break many behaviors, and telling "we will not support this behaviour " is not the solution
you are breaking things for a bad reason.

At least give a solution to avoid the plugin to be loaded in the importPlugin function

@ced1870 sadly you have to update your plugins as i did with mine.

The solution is to override the method registerListeners and avoid to call the constructor if the plugin must not be executed.

Example:

/**

  • Override registers Listeners to the Dispatcher
  • It allows to stop a plugin execution based on the return value of its constructor
    *
  • @override
  • @return void
    */

public function registerListeners() {
// Check if the plugin has not been stopped by the constructor
if(!$this->isPluginStopped) {
parent::registerListeners();
}
}

thank you for the details
I have already tested that,
it works in Joomla 4,
it does NOT work in Joomla 3

I have removed the __construct function, and overrided the registerListeners
as you say, this is sad

This is not sad, this is actually the right way to do.

so please explain why it does not work in joomla 3, if this is the way to do

@laoneo actually this is not the right way to do, this is the way that personally you had chosen, given that you wrote this part of the Joomla core.

I meant that this is the right way to do with the actual code. Not that my way is the only way you can do something. There always more than one way to do something.

ok but if I understand that, you said that the registerListeners override shall also be used in joomla 3, right ?
currently, I have 2 different behavior depending on J3 or J4. Can you please give me some details to see where I'm wrong

Was this page helpful?
0 / 5 - 0 ratings

Related issues

brianteeman picture brianteeman  路  6Comments

dougbevan picture dougbevan  路  4Comments

Didldu-Florian picture Didldu-Florian  路  4Comments

tuts-22 picture tuts-22  路  5Comments

mbabker picture mbabker  路  4Comments