? Pending

User tests: Successful: Unsuccessful:

avatar Fedik
Fedik
26 Apr 2020

Summary of Changes

This redo of #28785 but with events.
ping @wilsonge

Testing Instructions

Apply patch and make sure captcha works

Expected result

works

Actual result

works

Side note

@wilsonge I think Joomla have a little issue in events API, would be good to have some api to distinct private and global events.
Example the captcha has next events:
global: onPrivacyCollectAdminCapabilities
local: onInit, onDisplay, onCheckAnswer, onSetupField.

The global events should be loaded while PluginHelper::importPlugin('captcha');
And local only while instantiate of Joomla\CMS\Captcha\Captcha class.
Same goes for editor.

Currently if someone do:

PluginHelper::importPlugin('captcha');
PluginHelper::importPlugin('editors');
$app->dispatch('onInit');

That will call onInit for all active editors and cpatcha plugins, that of course make no sense.

This is not critical, but an old issue ?

avatar Fedik Fedik - open - 26 Apr 2020
avatar Fedik Fedik - change - 26 Apr 2020
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 26 Apr 2020
Category Libraries
avatar mbabker
mbabker - comment - 26 Apr 2020

?

You might as well rewrite captcha as not being plugins if you’re going this way. An event is an event, it really doesn’t matter whether it is emitted through a dispatcher with 100 listeners or 2 listeners.

You are misunderstanding the concept of an event system. An event is emitted so that anyone may subscribe to it to perform an action. Any possible listener may choose to act on an event or ignore it. It is not the responsibility of the code emitting the event to specify which listeners are eligible to receive the event.

The screw up in core is not using unique event identifiers, meaning you have things like “onInit” which have two totally different meanings to two totally different systems. “onInit” should be replaced with properly identifying event names.

avatar Fedik
Fedik - comment - 26 Apr 2020

In the end it still an events ?
not usual (in joomla context) but still:

Captcha::getInstance()->getDispatcher()
  ->addListener('onInit', ['foobar' => 'doSomething'])

“onInit” should be replaced with properly identifying event names.

This is much to do and b.c. and stuff, I am to lazy for it ?

avatar richard67
richard67 - comment - 26 Apr 2020

Does this PR solve issue #28800 ? I have created that issue after I had merged #28785 because @wilsonge asked me to do so. Shall I close the issue?

avatar Fedik
Fedik - comment - 26 Apr 2020

Yes and No, turns out it not that easy ?
will wait @wilsonge
then this pull or that issue can be closed

avatar mbabker
mbabker - comment - 26 Apr 2020

The fact you have to manually subscribe to a second dispatcher is exactly why this is problematic. A plugin should NEVER EVER EVER EVER have to manually call $dispatcher->addListener() and if it is a requirement then the core architecture is FUBAR.

Fact is, onInit needs to be deprecated as an event name and replaced with captcha.init and editor.init as event names (don't get me started with this "onFoo" naming convention, that's only a limitation of the 3.x and earlier code directly mapping event names to methods on a listener class). It gets rid of the ambiguity and issue of two incompatible subsystems emitting the same event. A short term fix until unique events are the only way is to include context information in the emitted event arguments (the same way all the "onContentFoo" stuff works) and tell developers to check context (like they should be on every event).

Using a "private" dispatcher might monkey patch your way around the original problem, but it is honestly just introducing a new problem in the grand scheme of things. You're better off keeping the 3.x style code over introducing another broken mechanism into the 4.0 code that would go away if someone had the foresight into fixing architectural issues like this in 5.0.

avatar Fedik
Fedik - comment - 27 Apr 2020

okau, that maybe makes sense, in Joomla context
I better close it for now

avatar Fedik Fedik - change - 27 Apr 2020
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2020-04-27 08:59:19
Closed_By Fedik
Labels Added: ?
avatar Fedik Fedik - close - 27 Apr 2020

Add a Comment

Login with GitHub to post a comment