Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.2] Remove class-level event dispatcher dependency in plugins #39387

Open
wants to merge 8 commits into
base: 5.2-dev
Choose a base branch
from

Conversation

SharkyKZ
Copy link
Contributor

@SharkyKZ SharkyKZ commented Dec 9, 2022

Summary of Changes

Currently, the use of event dispatcher in plugins has some issues. Joomla\CMS\Plugin\CMSPlugin requires the dispatcher to be passed to the constructor but under normal circumstances it is not used because the dispatcher is always overwritten when importing the plugins using Joomla\CMS\Plugin\PluginHelper::importPlugin(). This is allowed by the fact that Joomla\CMS\Extension\PluginInterface implements Joomla\Event\DispatcherAwareInterface which has a setter method for injecting the dispatcher. This, however, means that for plugins that do not require it in the constructor, the dispatcher is optional and may not be set. This does not make any sense for plugins. The dispatcher must be mandatory and made available explicitly when registering listeners with it.

This PR proposes:

  1. Deprecate the dispatcher as an argument for Joomla\CMS\Plugin\CMSPlugin::__construct().
  2. Deprecate Joomla\CMS\Extension\PluginInterface extending Joomla\Event\DispatcherAwareInterface.
  3. Deprecate not passing the dispatcher to Joomla\CMS\Plugin\PluginHelper::importPlugin().
  4. Add dispatcher argument to Joomla\CMS\Extension\PluginInterface::registerListeners(). Currently nullable to allow J4/J5 compatibility.

B/C break for developers

Plugin developers need to update the registerListeners() method signature to support both J4 and J5.

Testing Instructions

Test that plugins continue working. Login, edit content, run smart search indexer, etc.

Link to documentations

Please select:

  • Documentation link for docs.joomla.org: TBD

  • No documentation changes for docs.joomla.org needed

  • Pull Request link for manual.joomla.org: Plugin changes Manual#70

  • No documentation changes for manual.joomla.org needed

@HLeithner
Copy link
Member

This PR is not possible, this would break all plugins overriding the registerListeners method, which means you can't have a plugin which supports 4 and 5.

We need this in a way which is b/c.

@SharkyKZ
Copy link
Contributor Author

SharkyKZ commented Mar 9, 2023

It's true that existing plugins with overridden method would need to be updated to account for the new method signature. But such plugins will work with both 4.0 and 5.0. This is mentioned in the manual. And when interface method signature is changed again in 6.0 to require a dispatcher instance, no changes will be necessary. So a plugin that's updated with 5.0 signature today will end up working with 4.0, 5.0 and 6.0.

We need this in a way which is b/c.

Interesting. Can you post a link to the new versioning policy of Joomla? I've seen claims that it supposedly follows SemVer but that seems to have changed.

@Fedik
Copy link
Member

Fedik commented Apr 3, 2023

This changes can be done in b/c way, without changing method signatures:

  • keep DispatcherAwareInterface interface
  • call $plugin->setDispatcher($dispatcher) in PluginHelper::import(), as it already is
  • modify registerListeners() to throw an exception when $this->getDispatcher() return trash.

@HLeithner
Copy link
Member

@laoneo what would you say?

@SharkyKZ
Copy link
Contributor Author

SharkyKZ commented Apr 3, 2023

This changes can be done in b/c way, without changing method signatures:

* keep `DispatcherAwareInterface` interface

* call `$plugin->setDispatcher($dispatcher)` in `PluginHelper::import()`, as it already is

* modify `registerListeners()` to throw an exception when `$this->getDispatcher()` return trash.

🤦‍♂️
The point here is to get rid of the totally misused DispatcherAwareInterface. But, apparently, the project is going backwards, introducing -aware interfaces in places where they absolutely don't belong.

@Fedik
Copy link
Member

Fedik commented Apr 3, 2023

Why it is not belong, what is belong then? Sorry, I do not understand, maybe my knowledge just not enogh.
In current case for me no big diference here if it DispatcherAwareInterface or PotatoInterface ;)

I can also sugest other way around, without DispatcherAwareInterface:

  • add new method to PluginInterface, kind of registerListenersInDispatcher(?DispatcherInterface $dispatcher = null);
  • deprecate registerListeners()
  • add use of new method, and proxy it to registerListeners(), untill 6.x

And add description why and when registerListeners() should be removed, and replaced with new method.
Because after 1 year no one will remember what the heck is going on.

@Fedik
Copy link
Member

Fedik commented Apr 3, 2023

Hmhm, or you mean that DispatcherAwareInterface should be used only when Class triggers some event?
Well, then it may have a sense, even though it not an obvious thing.
Then a new method should be a less risky change, than changing existing, in current case.

@HLeithner HLeithner added Feature b/c break This item changes the behavior in an incompatible why. HEADS UP labels Apr 7, 2023
@wilsonge
Copy link
Contributor

So I think that removing the Dispatcher as a constructor argument is a good thing.

My only question would be do we want to go down this approach OR to have the dispatcher get the events out (which is how I think this was intended to work originally using the subscriber interface - i.e. https://github.com/joomla/joomla-cms/pull/39387/files#diff-76977b095cc108785d3c5026e26a2df447db05cd1ad28a0a22820cf72573965bR230-R234 ). I always assumed once we removed support for Joomla 3.x style plugins and moved people over to SubscriberInterface that we'd remove the entire registerListeners method.

introducing -aware interfaces in places where they absolutely don't belong

I totally agree with this.

@HLeithner HLeithner changed the base branch from 5.0-dev to 5.1-dev September 30, 2023 22:51
@HLeithner
Copy link
Member

This pull request has been automatically rebased to 5.1-dev.

@HLeithner HLeithner changed the base branch from 5.1-dev to 5.2-dev April 24, 2024 09:09
@HLeithner
Copy link
Member

This pull request has been automatically rebased to 5.2-dev.

@HLeithner HLeithner changed the title [5.0] Remove class-level event dispatcher dependency in plugins [5.2] Remove class-level event dispatcher dependency in plugins Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
b/c break This item changes the behavior in an incompatible why. HEADS UP Feature PR-5.0-dev PR-5.2-dev Unit/System Tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants