Fatal Error (500) Using Joomla 6.1 Core API - GetTemplate Issue In OnContentPrepareForm - Question | JoomShaper

Fatal Error (500) Using Joomla 6.1 Core API - GetTemplate Issue In OnContentPrepareForm

S-D CONSULTING

S-D CONSULTING

Helix Framework 3 days ago

Hi Joomshaper team,

I am writing to report a critical bug in the Helix Ultimate System Plugin that causes a 500 Internal Server Error when trying to create Articles or Tags via the native Joomla Core API (Web Services) in Joomla 6.1.0.

Some time ago, on Joomla 5.4.x, I created a component that creates Joomla articles, formatted in JSON so they can be formatted in Page Builder, creates tags and images, and adds an addon that correlates other articles with the same tags at the bottom.

After upgrading to Joomla 6.1, my script crashed with a 500 error. I thought the problem might be related to the update and more stringent changes to the Joomla API. After debugging, I discovered that the problem is HELIX (latest version), which constantly listens for every activity done in Joomla, even with the API.

Description of the issue: When pushing a POST request to the Joomla API to create a new article or tag, Joomla triggers the onContentPrepareForm event. The Helix Ultimate system plugin hooks into this event and attempts to fetch the active template at line 120 of plugins/system/helixultimate/helixultimate.php: $template = Factory::getApplication()->getTemplate(true);

Since the request is handled by the ApiApplication (which has no frontend template assigned, unlike SiteApplication), Joomla 6.1 throws a fatal InvalidArgumentException, crashing the entire API call.

Environment:

Joomla version: 6.1.0

PHP version: 8.x

Helix Ultimate version: last version

Error Log / Stack Trace:

CRITICAL 10.4.71.1 error Uncaught Throwable of type InvalidArgumentException thrown with message "Could not find template "system".". Stack trace: 
#0 [ROOT]/plugins/system/helixultimate/helixultimate.php(120): Joomla\CMS\Application\CMSApplication->getTemplate()
#1 [ROOT]/libraries/src/Plugin/CMSPlugin.php(386): PlgSystemHelixultimate->onContentPrepareForm()
#2 [ROOT]/libraries/vendor/joomla/event/src/Dispatcher.php(454): Joomla\CMS\Plugin\CMSPlugin->{closure:Joomla\CMS\Plugin\CMSPlugin::registerLegacyListener():370}()
#3 [ROOT]/libraries/src/MVC/Model/FormBehaviorTrait.php(196): Joomla\Event\Dispatcher->dispatch()
#4 [ROOT]/administrator/components/com_tags/src/Model/TagModel.php(190): Joomla\CMS\MVC\Model\FormModel->loadForm()
...
#12 [ROOT]/libraries/src/Application/ApiApplication.php(116): Joomla\CMS\Application\ApiApplication->dispatch()

Proposed Fix / Workaround:

I managed to temporarily fix the issue on my server by adding an early exit for API clients at the very beginning of the onContentPrepareForm method in helixultimate.php:

PHP
public function onContentPrepareForm(Form $form, $data)
{
    // Fix for Joomla API context
    if (\Joomla\CMS\Factory::getApplication()->isClient('api')) {
        return true; 
    }

    $doc = Factory::getDocument();
    // ... rest of the code
}

Could you please review this issue and include a proper context check in the next Helix Ultimate update? API automations are completely broken without this patch.

Thank you for your great work!

Best regards,

0
4 Answers
Ziaul Kabir
Ziaul Kabir
Accepted Answer
Support Agent 1 day ago #222571

Hi,

Thanks for the detailed report and for identifying the root cause.

We have forwarded this to our development team for further review and investigation. Your findings and suggested workaround are very helpful and will assist in addressing the issue properly.

We will keep you updated once we have more information.

Thanks for your patience.

Best regards,

0
S-D CONSULTING
S-D CONSULTING
Accepted Answer
1 day ago #222579

Thanks, I read that HELIX version 2.2.5 was released today, I think this fix hasn't been applied, correct?

0
S-D CONSULTING
S-D CONSULTING
Accepted Answer
1 day ago #222581

For additional information, I ran the HELIX update, but the error reoccurred and I applied the FIX again

At line 114 of helixultimate.php in plugin/system/helixultimate

        // --- FIX for API JOOMLA 6.1 ---
        if (\Joomla\CMS\Factory::getApplication()->isClient('api')) {
            return true; 
        }
        // --- END FIX ---
0
Ziaul Kabir
Ziaul Kabir
Accepted Answer
Support Agent 1 day ago #222586

Yes, it will be added in a future release.

Thanks for your feedback

0