? Feature ? PR-5.0-dev Pending

User tests: Successful: Unsuccessful:

avatar Fedik
Fedik
17 Jan 2023

Pull Request for Issue #28800 .

Summary of Changes

The patch improve Captcha plugins.
Now it can use a real events, and people stop confusing onDisplay (etc) callback with event.

How this work.
Here added a new event onCaptchaSetup and an Interface for CaptchaProvider class.
While this event the plugin should register own CaptchaProvider class in CaptchaRegistry.
The system will retrieve the requested Captcha type from that registry and call required methods, that defined by CaptchaProviderInterface

This is fully backward compatible.

Looking for feedback.
If all good we can do the same for Editor and its Buttons.

Techicaly now one plugin can provide multiple captcha, however for now the global configuration done per plugin.
But this can be extended in future, when need.

Testing Instructions

Apply patch, remove administrator/cache/autoload_psr4.php
Enable recaptcha_invisible and make sure it works.

Testing B/C:
Enable older recaptcha and make sure it works.

Actual result BEFORE applying this Pull Request

All works

Expected result AFTER applying this Pull Request

All works

Link to documentations

Please select:

avatar joomla-cms-bot joomla-cms-bot - change - 17 Jan 2023
Category Libraries Front End Plugins
avatar Fedik Fedik - open - 17 Jan 2023
avatar Fedik Fedik - change - 17 Jan 2023
Status New Pending
avatar dgrammatiko
dgrammatiko - comment - 17 Jan 2023

@Fedik could you also move the captcha plugin to service providers, like #39639

avatar laoneo
laoneo - comment - 17 Jan 2023

@Fedik could you also move the captcha plugin to service providers, like #39639

I would do this in a separate pr to not block each other.

avatar dgrammatiko
dgrammatiko - comment - 17 Jan 2023

Sure, will update later.

Probably leave that for another PR. I'm waiting for the Editors, EditorsXtd version

428b81f 17 Jan 2023 avatar Fedik phpcs
avatar Fedik Fedik - change - 17 Jan 2023
Labels Added: ? PR-4.3-dev
avatar Fedik Fedik - change - 17 Jan 2023
The description was changed
avatar Fedik Fedik - edited - 17 Jan 2023
avatar joomla-cms-bot joomla-cms-bot - change - 20 Feb 2023
Category Libraries Front End Plugins Libraries Front End Plugins Unit Tests
avatar Fedik Fedik - change - 20 Feb 2023
Labels Added: ?
avatar laoneo
laoneo - comment - 20 Feb 2023

Why do you don't you just use plugin events and plugins, instead of having a registry, etc.? From my understanding I just want to dispatch an event and the result contains the captcha. Why all these extra classes? I would also deprecate the Captcha class as it is only an unnecessary static singleton.

avatar Fedik
Fedik - comment - 20 Feb 2023

Why do you don't you just use plugin events and plugins

That what I am doing

From my understanding I just want to dispatch an event and the result contains the captcha.

No, that wrong. You cannot have it in that way, the event will be displatched for ALL installed captcha.

I would also deprecate the Captcha

This class to "rule them all", cannot be trashed.

avatar dgrammatiko
dgrammatiko - comment - 20 Feb 2023

@laoneo the registry concept is the correct approach not only for the Captcha but also for the Editor and the Auth plugins. All these plugins, as they are right now, dispatching events within an event which architecturally is wrong. What @Fedik is doing here is normalising to single event (if I understand the code correctly, haven't step through though) which is the right thing

avatar laoneo
laoneo - comment - 20 Feb 2023

So it means you can never have multiple captchas on one site?

avatar dgrammatiko
dgrammatiko - comment - 20 Feb 2023

So it means you can never have multiple captchas on one site?

No, you should be able to, as you can have multiple Editors, etc. The issue that Fedik is fixing here is that all these plugins basically used to be direct callbacks up to 3.x. J4 everything was converted to events but in reality the events were wrappers to the same methods (eg Editor->init()). The registry acts as event delegation, which imo is a good approach and a solid concept that will lead to less buggy code

avatar Fedik
Fedik - comment - 20 Feb 2023

hmhm, please look the code. That to much to explain ?

You can have many captcha, and many differen captchas on same page (one capctha per captcha field).

But you cannot use onDisplay event. Please follow linked issue.

avatar Fedik
Fedik - comment - 20 Feb 2023

I would also deprecate the Captcha

On second thought, maybe we could, and use Registry directly (or merge Captcha and CaptchaRegistry to single class).
But we do not have a clear way to access a "shared" class instance.

$registry = Factory::getContainer()->get(CaptchaRegistry::class);
$captcha = $registry->get('potato_captcha');

echo $captcha->display();

So maybe in joomla 8 ?
Look on the Captcha class as a comfortable helper.

avatar Fedik Fedik - change - 26 Mar 2023
Labels Added: PR-4.4-dev
Removed: PR-4.3-dev
avatar laoneo
laoneo - comment - 30 Mar 2023

I guess it is better to rebase this pr to the 5.0-dev branch, as it will get more attention for new features. Thanks for understanding.

avatar Fedik Fedik - change - 2 Apr 2023
The description was changed
avatar Fedik Fedik - edited - 2 Apr 2023
avatar Fedik Fedik - change - 2 Apr 2023
The description was changed
avatar Fedik Fedik - edited - 2 Apr 2023
avatar Fedik Fedik - change - 7 Apr 2023
Labels Added: PR-5.0-dev
Removed: PR-4.4-dev
avatar Fedik Fedik - change - 10 Apr 2023
Labels Added: ?
avatar Fedik Fedik - change - 23 Apr 2023
Title
[RFC] Make captcha plugins use plugin events
[5.0][RFC] Make captcha plugins use plugin events
avatar Fedik Fedik - edited - 23 Apr 2023
avatar Fedik Fedik - change - 10 Jun 2023
Labels Added: Feature
Removed: ?
avatar Fedik Fedik - change - 6 Aug 2023
Title
[5.0][RFC] Make captcha plugins use plugin events
[5.0][RFC][Events] Make captcha plugins use plugin events
avatar Fedik Fedik - edited - 6 Aug 2023
avatar HLeithner HLeithner - change - 21 Aug 2023
Status Pending Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2023-08-21 07:44:48
Closed_By HLeithner
avatar HLeithner HLeithner - close - 21 Aug 2023
avatar HLeithner HLeithner - merge - 21 Aug 2023
avatar HLeithner
HLeithner - comment - 21 Aug 2023

thanks

avatar Fedik Fedik - change - 5 Sep 2023
The description was changed
avatar Fedik Fedik - edited - 5 Sep 2023

Add a Comment

Login with GitHub to post a comment