No Code Attached Yet bug
avatar prinswebdevelopment
prinswebdevelopment
28 Nov 2025

Joomla 5.4 (but I see the same problem in 6.1):

Form:getInstance (libraries/src/Form/Form.php:1691) is deprecated. The replacement doesn't work the same way, however, because the old method uses a singleton pattern. If you currently use Model:preprocessForm in your model and want to edit a subform, it will no longer work. In the 'old' method, you can do this:

protected function preprocessForm(Form $form, $data, $group = 'content')
    {
        parent::preprocessForm($form, $data, $group);

        $subFormField = $form->getField('subform');

        $i = 0;
        foreach ($data->surveys as $key => $row) {
        
            $subForm = Form::getInstance('subform.surveys' . $i, $subFormField->__get('formsource'), ['control' => 'jform[surveys][survey' . $i . ']']);

			// create new field
			$field = new \SimpleXMLElement('<field></field>');
			$field->addAttribute('name', 'readonly_spacer');
            $field->addAttribute('type', 'spacer');
            $field->addAttribute('hiddenLabel', 'true');
            $field->addAttribute('description', Text::_('TEXT'));
            
            // Voeg het veld toe aan het formulier
            $subForm->setField($field);

        }
        $i++;
    }
}

But in the new method:

$subForm = Form::getInstance('subform.surveys' . $i, $subFormField->__get('formsource'), ['control' => 'jform[surveys][survey' . $i . ']']);

replaced:

$formFactory = Factory::getContainer()->get(FormFactoryInterface::class);
$subForm = $formFactory->createForm('subform.surveys' . $i, ['control' => 'jform[surveys][survey' . $i . ']']);
$subForm->load($subFormField->__get('formsource'));

This doesn't work because if the form is loaded in libraries/src/Form/Field/SubformField.php:385, a new object is created and the old one isn't reused. Furthermore, I believe it's impossible to edit a subform in the model.

avatar prinswebdevelopment prinswebdevelopment - open - 28 Nov 2025
avatar joomla-cms-bot joomla-cms-bot - change - 28 Nov 2025
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 28 Nov 2025
avatar prinswebdevelopment prinswebdevelopment - change - 28 Nov 2025
The description was changed
avatar prinswebdevelopment prinswebdevelopment - edited - 28 Nov 2025
avatar prinswebdevelopment prinswebdevelopment - change - 28 Nov 2025
The description was changed
avatar prinswebdevelopment prinswebdevelopment - edited - 28 Nov 2025
avatar prinswebdevelopment prinswebdevelopment - change - 28 Nov 2025
The description was changed
avatar prinswebdevelopment prinswebdevelopment - edited - 28 Nov 2025
avatar prinswebdevelopment prinswebdevelopment - change - 28 Nov 2025
The description was changed
avatar prinswebdevelopment prinswebdevelopment - edited - 28 Nov 2025
avatar Fedik Fedik - change - 6 Dec 2025
Labels Added: bug
avatar Fedik Fedik - labeled - 6 Dec 2025
avatar Fedik
Fedik - comment - 6 Dec 2025

The issue is similar to

But I would keep it open because it is more specific

avatar HLeithner HLeithner - change - 6 Dec 2025
The description was changed
avatar HLeithner HLeithner - edited - 6 Dec 2025
avatar HLeithner
HLeithner - comment - 6 Dec 2025

@prinswebdevelopment can you be more precisely? you copy code from 2 functions where I'm not sure which one is where and what code you mean has changed and what is no longer possible. please link the code in the cms where you no longer get the form object the way you need it. Or where you expect the form object and don't get the right one.

thanks

avatar prinswebdevelopment
prinswebdevelopment - comment - 8 Dec 2025

It’s not that complicated. Create a component with a form that contains a subform. In the component’s model, implement the preprocessForm() method. Modify the subform there by loading it via Form::getInstance(). When Joomla later renders the subform in the layout, the same instance is used, because getInstance() acts as a cache.

Although it is recommended to create Form objects via $formFactory->createForm(), doing so here is pointless. That method always creates a new form instance and does not use a cache. As a result, the subform used in the layout is recreated and any earlier changes are lost.

Joomla does not provide any other mechanism to preprocess subforms.

Add a Comment

Login with GitHub to post a comment