User tests: Successful: Unsuccessful:
Pull Request for Issue # .
The PR #39011 introduced namespace to the templates. This obviously solves the Fields problem but there is one more that needs to be tackled: com_ajax
.
This PR is using the existing conventions but allows to load the namespaced helper
helper.php
in the templates\cassiopeia
folder with the following content<?php
defined('_JEXEC') || die;
class TplCassiopeiaHelper
{
public static function templateAjax(): array
{
return ['is' => true, 'namespaced' => false];
}
}
index.php?option=com_ajax&method=template&format=json&template=cassiopeia
and you should have a message: {"success":true,"message":null,"messages":null,"data":{"is":true,"namespaced":false}}
<namespace path="src">Joomla\Template\Cassiopeia</namespace>
to the templateDetails.xml of Cassiopeiaadministrator/cache/autoload_psr4.php
templates/cassiopeia/src/Helper/AjaxHelper.php
with the following contents:<?php
namespace Joomla\Template\Cassiopeia\Site\Helper;
defined('_JEXEC') || die;
class AjaxHelper
{
public static function templateAjax(): array
{
return ['is' => true, 'namespaced' => true];
}
}
index.php?option=com_ajax&method=template&format=json&template=cassiopeia
and you should have a message: {"success":true,"message":null,"messages":null,"data":{"is":true,"namespaced":true}}
helper.php
in the administrator/templates/atum
folder<?php
defined('_JEXEC') || die;
class TplAtumHelper
{
public static function templateAjax(): array
{
return ['is' => true, 'namespaced' => false];
}
}
administrator/index.php?option=com_ajax&method=template&format=json&template=atum
and you should have a message: {"success":true,"message":null,"messages":null,"data":{"is":true,"namespaced":false}}
<namespace path="src">Joomla\Template\Atum</namespace>
to the templateDetails.xml of the Atum templateadministrator/cache/autoload_psr4.php
administrator/templates/atum/src/Helper/AjaxHelper.php
with the following contents:<?php
namespace Joomla\Template\Atum\Administrator\Helper;
defined('_JEXEC') || die;
class AjaxHelper
{
public static function templateAjax(): array
{
return ['is' => true, 'namespaced' => true];
}
}
administrator/index.php?option=com_ajax&method=template&format=json&template=atum
and you should have a message: {"success":true,"message":null,"messages":null,"data":{"is":true,"namespaced":true}}
Please select:
Documentation link for docs.joomla.org:
No documentation changes for docs.joomla.org needed
Pull Request link for manual.joomla.org:
No documentation changes for manual.joomla.org needed
Requesting a review from @HLeithner @laoneo @wilsonge
Category | ⇒ | Front End com_ajax |
Status | New | ⇒ | Pending |
Labels |
Added:
PR-4.3-dev
|
That's why template interface is needed for something like this.
You're welcome to propose a better solution, I'm just monkey patching things here so that a namespaced template could still use the com_ajax functionality...
I thought about this and think it's completely the wrong approach, the helper class has zero context. Has no idea in which application context it's running. This is the opposite as the way joomla is going.
I'm against this PR and removing the com_ajax template at some point in time. The preferred way to do this is using a plugin.
Also the module is questionable, because it's also context less. Looking at the way how webservices work I think it's better to follow a event system why and not allow to by-pass the single entry point approach.
I know I said it doesn't go away anytime soon, but that doesn't mean we have to support it in new code. I will bring this up in maintainers chat and try to get some feedback
I'm against this PR and removing the com_ajax template at some point in time. The preferred way to do this is using a plugin. Also the module is questionable, because it's also context less.
The "questionable" com_ajax for all the supported parts (plugins
, modules
and templates
) would be nice to go away IF Joomla itself provided an easy way to produce the same output (JSON or HTML) using partials, as WP does. Joomla's ability to render partials, atm, requires an extra entry file on the active template and even in that case a component is always needed in the front end (the routing part) so rendering a module similar to com_ajax requires quite some work. The idea to remove those helpers without a viable alternative doesn't look that appealing, esp for people that don't want to write a tonne of PHP (plugins, extra entry files on the template, etc)
I know I said it doesn't go away anytime soon, but that doesn't mean we have to support it in new code.
It would be nice to either have complete namespace support (eg also the helper) or properly deprecate the thing and remove it ASAP.
In conclusion: I have code that requires com_ajax (both for modules and templates, thus the PR), so a definite answer here would be nice. Keep in mind that the helper in all 3 contexts IS a very easy escape hatch for front enders that need some server side code without going too deep creating components or plugins. Requiring a plugin for those cases pushes front enders away from the project rather than inviting them...
My 2c, and Happy new year
Status | Pending | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2023-01-15 17:10:06 |
Closed_By | ⇒ | dgrammatiko |
Class names must not be hardcoded. That's why template interface is needed for something like this.