I've noticed that Joomla's Plugin Events are very inconsistent. For example, onDisplay event in editors and editors-xtd are very different. I am aware that the display will not be the same for different type of content or different feature. However, the method's arguments should always be the same (or generic) and allows the body to be flexible. That way, as developer, when we extend the JPlugin and implement events, we know exactly what to expect in the callback of the events.
onDisplay is just an example. I've noticed there's a ton more.
Having generic arguments for Events. For instance, onDisplay(array $context=[]). This way, if in my plugin, if I expect "name" element, I can check and implement my code accordingly.
Labels |
Added:
?
|
Title |
|
Labels |
Added:
J4 Issue
|
onDisplay
is not really an Event, it used like a callback
https://github.com/joomla/joomla-cms/blob/4.0-dev/libraries/src/Editor/Editor.php#L200 same for buttons.
You should not expect that it triggered as Event for all plugins.
Status | New | ⇒ | Discussion |
@Fedik, check here:
https://docs.joomla.org/Plugin/Events
Regardless, the inconsistency is there and it should be genericized. See my suggestion in the proposed solution.
Another option is something like this:
public function onEventName() {
$args = func_get_args();
// implement the details here...
}
Or
// EventContext can be something like \Joomla\CMS\EventContext
public function onEventName(EventContext $context) {
// implement the details here...
}
Basically, an event should be very generic.
@webconsolinc please submit a pr should be more easier to discuss further with some code
Basically, an event should be very generic.
Actually, no. An event should be emitted with a consistent set of parameters, typically encapsulated within an event object (which 4.0 supports, but because of 15 years of B/C most events aren't triggered that way and I get the feeling core will never fully embraced this level of encapsulation). The parameters should not be different regardless of where an event is triggered in the system; what can be different is the data contained within those parameters (i.e. a $context
if something needs to distinguish the context the event is triggered from). If you're having to use func_get_args()
in a listener to decide how to handle an event, that is already a code smell as listeners generally should only be subscribed to one event.
If onDisplay
is being emitted as an event from two different contexts with two different sets of parameters, this is broken and one of those contexts should be refactored to use a different event. As pointed out, onDisplay
actually isn't being emitted as an event in certain circumstances. So trying to compare the two contexts is like saying "every call to a onDisplay
method in any class should always have the same signature".
As @Fedik pointed out, there isn't an "onDisplay" event in the editor API (and the documentation page is wrong for listing it as an event), it is a callback explicitly called by another method in the Editor class. There IS an "onDisplay" event in the Captcha API though, and this one is a proper event.
so we should fix documentation only, in your hopinion.?
... sounds reasonable... or wait.... still thinking ...
but because of 15 years of B/C ...
that's the point where i start to loose myself
The docs should be fixed to accurately reflect onDisplay
isn't an event in the Editor API.
@mbabker, that's fair.
Keep in mind, I just raised onDisplay as an example and as it also listed as an Event on Joomla! Website. Now we know that it's wrong. So, what documentation can the community rely on?
Also, my report was related to 3.9.6, and not 4.0. I didn't log it as bug as I didn't see it as a bug. However, I saw it as serious inconsistency issue.
Now, there are other "Events" (I don't know if I should call them events now), such as:
onInit and a few others that I saw, there's similar inconsistency issue. Are they just callback? If so, where exactly can I use as a reference when I need to build Plugin to listen to events?
I have added a short information on https://docs.joomla.org/Plugin/Events/Editor#Description_3
So, what documentation can the community rely on?
A documentation that is kept up-to-date by the "community" ;-) Everybody is welcome to help.
@RaLater how do I get involved to be able to contribute to code and documentation?
This two pages could be a good starting point :)
how do I get involved to be able to contribute to code
https://docs.joomla.org/Special:MyLanguage/Portal:Developers
how do I get involved to be able to contribute to [...] documentation
https://docs.joomla.org/JDOC:How_to_Contribute_to_Joomla!_Documentation
I guess there is nothing more to discuss on this issue, so I'm closing. Feel free to re-open if you still want to discuss about this issue further. Thanks !
Status | Discussion | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2022-11-16 08:53:59 |
Closed_By | ⇒ | joomdonation | |
Labels |
Added:
No Code Attached Yet
Removed: ? |
Changed Label as new Features go in J4.