0

If I want to add a Subform to my Module I need to specify the "formsource" (path to xml) into my fieldsettings. But is there a way to use The Autoloader and "simply" use the Form name? In the docs it's written "[...]formsource (mandatory) the form source to be included. A relative path to the xml file (relative to the root folder for the installed Joomla site) or a valid form name which can be found by JForm::getInstance()..." So my question now is - is there a way to use the name here also in modules now?

So when using the new Filestructure for Modules I think i need to register the namespace for Forms (and Fields) in my provider.php, and if so how to do this ?

My current provider.php:

return new class() implements ServiceProviderInterface
{
    public function register(Container $container): void
    {
        $container->registerServiceProvider( new ModuleDispatcherFactory('\\CMP\\Module\\Modulename'));
        $container->registerServiceProvider( new HelperFactory('\\CMP\\Module\\Modulename\\Site\\Helper'));
        $container->registerServiceProvider( new Module());
    }
};

File Structure:

mod_modulename
 - forms
 -- subform.xml
 ...
 - services
 -- provider.php
 - src
 -- Dispatcher
 - mod_modulename.xml
 ...

mod_modulename.xml:

...
<field 
   name="title_source_params"
   type="subform"
   formsource="modules.mod_modulename.subform"
/>
...

Error: Joomla\CMS\Form\Form::getInstance() could not load file

Again, I know i could simply paste in the path to the xml in the formsource but does it work / what do I need to do to use the formname instead?

1 Answer 1

1

No, documentation is wrong and this wouldn't make much sense anyways. Joomla\CMS\Form\Form::getInstance() can either retrieve a cached form instance by name or create a new one. But in order to create a new instance, a valid XML file or XML string is required. Your subform is the first time where your form is being instantiated so the XML file/source is mandatory. Anyways, Joomla\CMS\Form\Form::getInstance() is deprecated. Form instances will no longer be cached in the future.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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