No Code Attached Yet bug
avatar artur-stepien
artur-stepien
24 Apr 2024

Steps to reproduce the issue

Unable to use FormModelInterface::getForm() method outside of a component execution. Because FormBehaviorTrait::loadForm() uses JPATH_COMPONENT constant to register paths to form object. This results in a could not load file error when trying to load form on a page where desired component is not loaded or in cli/scheduled task. I consider it a bug as component booting doesn't apparently boot the component fully.

Expected result

Form is being loaded.

Actual result

could not load file error

System information (as much as possible)

Joomla 4.x, 5.x and 6.x

Additional comments

The root of this problem is this part in line 73 of https://github.com/joomla/joomla-cms/blob/4.4-dev/libraries/src/MVC/Model/FormBehaviorTrait.php

        // Get the form.
        Form::addFormPath(JPATH_COMPONENT . '/forms');
        Form::addFormPath(JPATH_COMPONENT . '/models/forms');
        Form::addFieldPath(JPATH_COMPONENT . '/models/fields');
        Form::addFormPath(JPATH_COMPONENT . '/model/form');
        Form::addFieldPath(JPATH_COMPONENT . '/model/field');

I would propose to register those paths in Joomla\CMS\MVC\Factory\MVCFactory::createModel() method to avoid issues when component is booted outside of component execution.

avatar artur-stepien artur-stepien - open - 24 Apr 2024
avatar joomla-cms-bot joomla-cms-bot - change - 24 Apr 2024
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 24 Apr 2024
avatar Fedik Fedik - change - 24 Apr 2024
Labels Added: bug
avatar Fedik Fedik - labeled - 24 Apr 2024

Add a Comment

Login with GitHub to post a comment