Pull Request for Issue #32136 .
Modify com_ajax to support namespace module.
public static function getDataAjax()
{
$data = ['test'];
return $data;
}
Before patch, you will get this error
{"success":false,"message":"The file at mod_articles_categories/helper.php does not exist.","messages":null,"data":null}
After patch, you will get this success response:
{"success":true,"message":null,"messages":null,"data":["test"]}
You can install the modified mod_articles_categories.zip which I attached here so that you don't have do the step #2 (modify code)
mod_articles_categories.zip
Tested as explained.
Works as expected in the description.
But you can extend the module interface to get the module helper class. SOmething like $app->bootModule($module->module, $app->getName())->getHelper();
for example. Then getHelper does all the internal loading and returns the helper object. I mean it is just an idea but much better than compiling class names and loading files through require which we not should do anymore in J4.
So basically, move the logic to load helper class to https://github.com/joomla/joomla-cms/blob/4.0-dev/libraries/src/Extension/Module.php ?
You can either move your logic there. Better and cleaner way would be to introduce a helper factory, similar to what we did with the dispatcher factory https://github.com/joomla/joomla-cms/blob/4.0-dev/libraries/src/Dispatcher/ModuleDispatcherFactory.php. Guess @wilsonge needs to give here his input what he would accept for 4.0.
Something like $app->bootModule($module->module, $app->getName())->getHelper(); for example.
@laoneo problem with Helper, they all "static", I mean they is "abstract",
so in current state the factory cannot build "helper instance", only return the class name of the helper
Perhaps we need to get rid of static then.
For the time being, how about adding a method to ModuleHelper https://github.com/joomla/joomla-cms/blob/4.0-dev/libraries/src/Helper/ModuleHelper.php to return the helper class?
hm, what if we try Anonymous classes? ->getHelper()
will return :
new class extends $helperClass{}
but it a bit dirty
Another idea, something like:
$dispatcher = $app->bootModule($module->module, $app->getName())->getDispatcher($module, $app);
$dispatcher->dispatchHelper('onAjaxFooBar');
Because a loot of helpers use Helper::doFooBar($module, $params)
it could be useful when it will be a part of dispatcher
.
But maybe also not a very good idea.
For the time being, how about adding a method to ModuleHelper
Would be better if we find solution now, because it will stay forever
@laoneo perhaps at this point we need to do something about a getNamespace
utility. Either save it in the manifest JSON part of the extension at install, or read it from XML the declaration. Either way I'm fine with any decision and hopeful of things moving forward.
I say let's start with my commit #30816 (RTC now) since it will be required by this commit and child templates features.
@thednp getNamespace
is the wrong direction. Because we want to get away from manually compiling class names all over Joomla. The right approach would be to use some factories and inject them wherever possible to load the helpers. I know it is a bit more effort but it will payout at the end. Testing will be much more easier on a long term.
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2021-03-10 15:51:32 |
Closed_By | ⇒ | joomdonation | |
Labels |
Added:
?
?
|
Category | ⇒ | Front End com_ajax |
@joomdonation you shouldn't close it that fast. Perhaps I'm on the wrong path too
@joomdonation I hope you re-commit this PR with updates for #32633
@joomdonation you shouldn't close it that fast. Perhaps I'm on the wrong path too
?
Was waiting for your PR, hehe.
Hi guys, I know this issue is already closed but has this issue really been resolved? It's still returning The file at mod_articles_categories/helper.php does not exist in Joomla 4.0.3. and com_ajax still looks for Mod class prefix in helper class name.
Better to use the Joomla 4 way and boot the module. Then you don't have to manually include the file. How to load the helper can then be done with extending the module interface. But manually construction namespaces and class names should be something of the past.