? J4 Issue ?
avatar joeforjoomla
joeforjoomla
15 May 2019

Steps to reproduce the issue

@laoneo after your PR #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

avatar joeforjoomla joeforjoomla - open - 15 May 2019
avatar joomla-cms-bot joomla-cms-bot - change - 15 May 2019
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 15 May 2019
avatar joeforjoomla
joeforjoomla - comment - 15 May 2019

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

avatar franz-wohlkoenig franz-wohlkoenig - change - 15 May 2019
Status New Discussion
avatar laoneo
laoneo - comment - 16 May 2019

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.

avatar joeforjoomla
joeforjoomla - comment - 16 May 2019

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

avatar laoneo
laoneo - comment - 16 May 2019

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.

avatar franz-wohlkoenig franz-wohlkoenig - change - 20 May 2019
Labels Added: J4 Issue
avatar franz-wohlkoenig franz-wohlkoenig - labeled - 20 May 2019
avatar infograf768 infograf768 - change - 6 Feb 2020
Labels Added: ?
avatar infograf768 infograf768 - labeled - 6 Feb 2020
avatar jwaisner jwaisner - change - 17 Feb 2020
Priority Medium Urgent
avatar joomla-cms-bot joomla-cms-bot - change - 17 Feb 2020
Labels Removed: ?
avatar joomla-cms-bot joomla-cms-bot - unlabeled - 17 Feb 2020
avatar jwaisner
jwaisner - comment - 17 Feb 2020

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.

avatar jwaisner jwaisner - change - 17 Feb 2020
Labels Added: ?
avatar jwaisner jwaisner - labeled - 17 Feb 2020
avatar wilsonge wilsonge - change - 20 Feb 2020
Labels Added: ? ?
Removed: ?
avatar wilsonge wilsonge - labeled - 20 Feb 2020
avatar wilsonge
wilsonge - comment - 1 Mar 2020

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

avatar wilsonge wilsonge - change - 1 Mar 2020
Status Discussion Closed
Closed_Date 0000-00-00 00:00:00 2020-03-01 19:17:28
Closed_By wilsonge
Labels Added: ?
Removed: ?
avatar wilsonge wilsonge - close - 1 Mar 2020
avatar wilsonge wilsonge - change - 1 Mar 2020
Labels Removed: ?
avatar wilsonge wilsonge - unlabeled - 1 Mar 2020
avatar ced1870
ced1870 - comment - 22 Oct 2020

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

avatar joeforjoomla
joeforjoomla - comment - 22 Oct 2020

@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();
}
}

avatar ced1870
ced1870 - comment - 23 Oct 2020

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

avatar laoneo
laoneo - comment - 23 Oct 2020

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

avatar ced1870
ced1870 - comment - 23 Oct 2020

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

avatar joeforjoomla
joeforjoomla - comment - 23 Oct 2020

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

avatar laoneo
laoneo - comment - 23 Oct 2020

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.

avatar ced1870
ced1870 - comment - 23 Oct 2020

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

Add a Comment

Login with GitHub to post a comment