1

I've been developing a custom component on Joomla 4 for a few months now and I've finally got round to working on the access and permissions side of things. Whenever I try to access the Options for my component, I'm getting a Form::loadForm could not load file error. I think I may have created config.xml after installing this initial version, so that may be why something isn't configured properly to enable Joomla to access it.

I have installed the latest version of my component on a fresh Joomla 4 test site and the Options are all working correctly. I've searched through the databases for both Joomla installations and compared any entries connected to when my component was installed and I can't find any relevant reference or setting.

I know that installing the component from new will work properly, I'm just curious as to what I'm missing when it comes to applying a manual fix to my earlier iteration. If anyone can help point me in the right direction it would be much appreciated.

1 Answer 1

2

The error message is being displayed because there is an issue with the name of the config.xml or the path where it is located. There are no references stored in the data base relevant to the issue.

The error message in your opening post only appears in libraries/src/MVC/Model/FormBehaviorTrait.php at line #101 as part of method LoadForm() starting at line #50.

loadForm() is called by administrator/components/com_config/src/Model/ComponentModel.php at line #86 just after an attempt is made to add the Path where config.xml should be found.

The code just prior to and including the call to loadForm().

if ($path = $state->get('component.path'))
{
    // Add the search path for the admin component config.xml file.
    Form::addFormPath($path);
}
else
{
    // Add the search path for the admin component config.xml file.
    Form::addFormPath(JPATH_ADMINISTRATOR . '/components/' . $option);
}

// Get the form.
$form = $this->loadForm(
    'com_config.component',
    'config',
    array('control' => 'jform', 'load_data' => $loadData),
    false,
    '/config'
);

I was able to generate the error message you are receiving by misspelling config.xml and on a case sensitive environment changed the config.xml to Config.xml and it too caused the message to appear. A typo or upper/lowercase issue in the path would also cause the same message.

You might like to look at what the values of $source and $xpath is at line #99 of libraries/src/MVC/Model/FormBehaviorTrait.php

if ($form->loadFile($source, false, $xpath) == false)
{
    throw new \RuntimeException('Form::loadForm could not load file');
}

to see why it is getting flagged as false.

1
  • Thanks Irata - that really helped. I traced the process for calculating the path and managed to work out what the issue was. Whilst I'm developing my component, all the files for it are being stored in a location outside of localhost and I'm sim-linking to them instead. This generally works absolutely fine, but by doing this, it was confusing the way loadForm calculates the path to config.xml. Once I'd replaced the sim-link with an actual instance of config.xml in the correct location it all started working properly :)
    – Grant Hood
    Aug 13 at 8:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.