I have a file test.php
that manually loads the Joomla framework and prints template parameters.
<?php
// test.php, located in the same directory that index.php is
define('_JEXEC', 1);
define('JPATH_BASE', '.');
require_once(JPATH_BASE . '/includes/defines.php');
require_once(JPATH_BASE . '/includes/framework.php');
$container = \Joomla\CMS\Factory::getContainer();
$container->alias('session.web', 'session.web.site')
->alias('session', 'session.web.site')
->alias('JSession', 'session.web.site')
->alias(\Joomla\CMS\Session\Session::class, 'session.web.site')
->alias(\Joomla\Session\Session::class, 'session.web.site')
->alias(\Joomla\Session\SessionInterface::class, 'session.web.site');
$app = $container->get(\Joomla\CMS\Application\SiteApplication::class);
\Joomla\CMS\Factory::$application = $app;
// Uncomment to mitigate the error:
// JLoader::registerNamespace('Joomla\Component\Templates\Administrator', JPATH_ADMINISTRATOR . '/components/com_templates/src');
$templateParams = $app->getTemplate(true)->params;// error (see explanation below)
var_dump($templateParams);
In Joomla 4.1, the call to app->getTemplate(true)
works fine because the function makes the database calls itself.
In Joomla 4.2, the call to app->getTemplate(true)
delegates the database calls to the com_templates
service provider (I'm not exactly sure how). But since the Joomla\Component\Templates\Administrator\Extensions
namespace isn't loaded, we get a ClassNotFoundError
for class TemplatesComponent
.
Below is the stack trace:
Symfony\Component\ErrorHandler\Error\ClassNotFoundError:
Attempted to load class "TemplatesComponent" from namespace "Joomla\Component\Templates\Administrator\Extension".
Did you forget a "use" statement for another namespace?
at /srv/http/administrator/components/com_templates/services/provider.php:47
at Joomla\DI\ServiceProviderInterface@anonymous/srv/http/administrator/components/com_templates/services/provider.php:28$484->{closure}()
(/srv/http/libraries/vendor/joomla/di/src/ContainerResource.php:182)
at Joomla\DI\ContainerResource->getInstance()
(/srv/http/libraries/vendor/joomla/di/src/Container.php:96)
at Joomla\DI\Container->get()
(/srv/http/libraries/src/Extension/ExtensionManagerTrait.php:174)
at Joomla\CMS\Application\CMSApplication->loadExtension()
(/srv/http/libraries/src/Extension/ExtensionManagerTrait.php:50)
at Joomla\CMS\Application\CMSApplication->bootComponent()
(/srv/http/libraries/src/Application/SiteApplication.php:442)
at Joomla\CMS\Application\SiteApplication->getTemplate()
(/srv/http/test.php:23)
If I add $app->getTemplate(true)
to an HtmlView::display()
function, it works just fine and a var_dump
shows what I'd expect.
So I was wondering if I was initializing the Joomla framework wrong or something.
HtmlView::display
function did you change exactly?administrator/cache/autoload_psr4.php