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 1 month 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
11 Answers
Ziaul Kabir
Ziaul Kabir
Accepted Answer
Support Agent 1 month 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 month 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 month 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 month ago #222586

Yes, it will be added in a future release.

Thanks for your feedback

0
M
Michael
Accepted Answer
1 month ago #223274

I have applied the FIX on my Joomla 6.1 and confirm it's working

0
M
Michael
Accepted Answer
1 month ago #223216

I also use the Joomla Core API with Helix Ultimate System Plugin and get the same internal server error 500. When will this issue be fixed?

0
S-D CONSULTING
S-D CONSULTING
Accepted Answer
1 month ago #223219

Hi Michael, even with the latest Helix 2.2.5 update, the issue hasn't been resolved, but I reported it shortly before the release.

My workaround is currently working, and the APIs merged with the processes I created are maintaining all the correct processes.

0
Ziaul Kabir
Ziaul Kabir
Accepted Answer
Support Agent 1 month ago #223218

This will be added in an upcoming release.

However, we are unable to provide an exact timeframe at this moment.

Thank you for your understanding.

Best regards,

0
S-D CONSULTING
S-D CONSULTING
Accepted Answer
3 weeks ago #223803

Hi, I saw that Helix version 2.2.6 has just been released. I would like to know if the issue highlighted in this ticket has been fixed. This is very important because before upgrading, I need to be sure that it doesn't block Joomla's API functions again.

0
Ziaul Kabir
Ziaul Kabir
Accepted Answer
Support Agent 3 weeks ago #223832

No, This issues still not fixed in this version of Helix Ultimate and it will be added in next release.

Thanks for your understanding.

0
S-D CONSULTING
S-D CONSULTING
Accepted Answer
3 weeks ago #223851

Okay, thanks for the reply. I emphasize the importance of this update, as not everyone uses only the basic Joomla features. The Joomla APIs are very robust and efficient and are widely used. Unfortunately, in this case, HELIX is confirming its invasion of functions it shouldn't touch.

I tested the fix I proposed, and it also works on Helix 2.2.6. I'm writing this primarily for anyone who has encountered the same problem, as it's a simple one-line fix.

0