@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?
Labels |
Added:
?
|
Status | New | ⇒ | Discussion |
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.
Labels |
Added:
J4 Issue
|
Labels |
Added:
?
|
Priority | Medium | ⇒ | Urgent |
Labels |
Removed:
?
|
Increasing priority as per guidelines for beta-blockers.
Labels |
Added:
?
|
Labels |
Added:
?
?
Removed: ? |
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
Status | Discussion | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2020-03-01 19:17:28 |
Closed_By | ⇒ | wilsonge | |
Labels |
Added:
?
Removed: ? |
Labels |
Removed:
?
|
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
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
More specifically it seems that this happens because you move the registerListeners() out of the CMSPlugin __construct to the PluginHelper class