I hzve plugin with name PlgQuickiconResetMediaVersion
and method onAjaxResetMediaVersion
Please note that all names are in camel case
In joomla 3.x this works fine
But in Joomla 4.x is not work
Why?
This happens because the component com_ajax gets the plugin name from the browser address bar "as is" and just capitalizes the first letter
joomla-cms/components/com_ajax/ajax.php
Lines 154 to 163 in 27ffee6
If i call index.php?option=com_ajax&plugin=resetmediaversion&group=quickicon&format=json
then the component will receive onAjaxResetmediaversion
If i call index.php?option=com_ajax&plugin=ResetMediaVersion&group=quickicon&format=json
then the component will receive onAjaxResetMediaVersion
If i call index.php?option=com_ajax&plugin=resetMediaVersion&group=quickicon&format=json
then the component will receive onAjaxResetMediaVersion
If i call index.php?option=com_ajax&plugin=resetmediaVERSION&group=quickicon&format=json
then the component will receive onAjaxResetmediaVERSION
Of the 4 listed options, only the 2nd and 3rd will be processed correctly. They convert method name to onAjaxResetMediaVersion
This happens because the dispatcher registers methods through reflection.
joomla-cms/libraries/src/Plugin/CMSPlugin.php
Lines 202 to 203 in 27ffee6
That is, we make the relationship between the method name and the event name case-sensitive.
Perhaps it's good when all calls are made through code. But when a call is made, with parameters obtained from the browser string, this creates some inconvenience.
Maybe it is worth registering methods in lower case in dispatcher? This should not lead to ambiguity because php itself regulates this. I cannot declare in the same class myFunction
and myfunction
.
But that will allow you to avoid ambiguity when calling events. I can call onAjaxMyAwesomeMethodOfClass
and onAjaxmyawesomemethodofclass
This will make my plugin code look conveniently readable
How sane is this?
Labels |
Added:
No Code Attached Yet
|
Thanks for opening this issue. This behavior was bothering me too, not a fan of having to do impure CamelCase.
I needed sleep when I wrote this. In any case I think the suggestion is worth considering.
the plugin var from the url directly to calling a method of that name
nope, look closer ;)
Labels |
Added:
bug
|
I would actually say there is a @joomla/security issue here (a slight one) as Joomla is passing the raw value (able it ucfirst) of the plugin var from the url directly to calling a method of that name...