Search code examples
phpjoomla3.0joomla-component

Joomla Custom Component - Error loading form file


Currently, I've been trying to get familiar with programming custom components for Joomla 3.4.8. Therefore I've installed a new joomla website on my Raspberry Pi 2 for test purposes. Everything is working as it schould.

Then I started to do the 'Developing an MVC Component' Tutorial provided by Joomla itself. Everything worked fine until the point 7 'Using the database'.

Although this point talks about the database, the problem is to get the field types to work. I.e. when I want to add a new menu item (in the administrator part), and I select the custom menu item type, I get an error which states "Error loading form file".

I've been trying to find the error for several days, without success. I even went so far to track the code line inside the joomla framework which throws this error. The code line is inside /libraries/legacy/model/form.php (line 192). At this line you can see $this->preprocessForm($form, $data);. But somehow the code does not even enter this method, it simply throws an exception.

I compared the $form and $data variable with the ones from a normal run by adding the following statement (found here) before the line 192:

 echo "<pre>"; print_r($arr); echo "</pre>"; 

The $form variables does not have any difference. The $data variables however are slightly different. Unfortunately I'm pretty new to these concepts, so I don't really know what could be wrong or where to search for the problem.

Hopefully, somebody of you can help me out...

For completion here is the output of the $data variable when the error is triggered:

    Array
(
    [parent_id] => 1
    [level] => 
    [lft] => 
    [rgt] => 
    [alias] => 
    [id] => 
    [menutype] => mainmenu
    [title] => 
    [note] => 
    [path] => 
    [link] => index.php?option=com_helloworld&view=helloworld
    [type] => component
    [published] => 
    [component_id] => 10000
    [checked_out] => 
    [checked_out_time] => 
    [browserNav] => 0
    [access] => 
    [img] => 
    [template_style_id] => 0
    [params] => Array
        (
            [menu-anchor_title] => 
            [menu-anchor_css] => 
            [menu_image] => 
            [menu_text] => 1
            [page_title] => 
            [show_page_heading] => 
            [page_heading] => 
            [pageclass_sfx] => 
            [menu-meta_description] => 
            [menu-meta_keywords] => 
            [robots] => 
            [secure] => 0
        )
    [home] => 0
    [language] => 
    [client_id] => 
    [request] => Array
        (
            [option] => com_helloworld
            [view] => helloworld
        )
    [menuordering] => 0
    [toggle_modules] => 1
)

Solution

  • Okay! I finally solved the issue. Unfortunately it was a very stupid mistake...

    First of all I noticed that method preprocessForm($form, $data) had been overwritten by the subclass. Hence my echo statements wouldn't be executed. This brought me down to the point where my xml file at <joomla-root>/components/com_helloworld/views/helloworld/tmpl/default.xml was loaded.

    Unfortunately it didn't work. And this was due to a minor mistake in the xml file. The mistake was very simple and stupid:

    <fieldset name="request">
            <field
                name="id"
                type="helloworld"
                label="COM_HELLOWORLD_HELLOWORLD_FIELD_GREETING_LABEL"
                description="COM_HELLOWORLD_HELLOWORLD_FIELD_GREETING_DESC" 
                />
            </field>
    </fieldset>
    

    I simply closed the field tag twice, where the second closing tag was used in a previous step of the tutorial.

    Very stupid mistake which cost me several hours. At least I had some insights to the joomla code. Hopefully this post avoids others searching countless hours for such a minor mistake.