Joomla 3.3 - Adding custom fields to all menu items via plugin - params not saved
Asked Answered
M

1

6

I have a problem when adding custom fields to the com_menus - item view.

Tutorial: (see: http://docs.joomla.org/Adding_custom_fields_to_core_components_using_a_plugin)

The tutorial works great (com_contact), but when I want to cover the menu-item view: The parameters are not being saved!!!

Below is the code that I am using to determine the component and the view for adding the custom form.

class plgContentPluginName extends JPlugin {

    function onContentPrepareForm($form, $data) {

        $app = JFactory::getApplication();
        $option = $app->input->get('option');
        $view = $app->input->get('view');

        switch($option) {

                case 'com_menus': {
                    if ($app->isAdmin() && $view == 'item') {
                            JForm::addFormPath(__DIR__ . '/forms');
                            $form->loadFile('item', false);
                    }
                    return true;
                }

        }
        return true;

    }   
}

Here is the item.xml that is being loaded (/forms/item.xml)

<?xml version="1.0" encoding="UTF-8"?>    
<form>
        <fields name="params">
                <fieldset name="params" label="Custom Fields">
                        <field name="param1" type="text" label="lbltext"/>
                        <field name="param2" type="text" label="lblText2"/>
                </fieldset>
        </fields>
    </form>

The form is being rendered properly when I am creating or editing a menu item, but the values are not being saved when I hit "Save".

Thanks.

Meissen answered 14/9, 2014 at 10:21 Comment(3)
It's perhaps best to ask the author(s) of the documentation (normally done within the bugtracker) about your problem (normally done as bug or documentation report). Have you tried that? And have you double checked with the API source code that setting such a configuration value to NULL is actually possible and within what the API has been created for? NULL most often is a special value as it denotes something as "not having any value".Haland
I created a new issue (issues.joomla.org/tracker/joomla-cms/5289), hopefully this will help.Meissen
+1 for the question - I'm running in to the same problem. What is needed to save the new fields/values to the database? The link you provided to the joomla issue isn't clear on how to make this work. Can you post how you resolved this?Summons
M
4

I solved this by just removing the $view == 'item' condition in the If block.

Finally looks like this:

class plgContentPluginName extends JPlugin {

function onContentPrepareForm($form, $data) {

    $app = JFactory::getApplication();
    $option = $app->input->get('option');

    switch($option) {

            case 'com_menus': {
                if ($app->isAdmin()) {
                        JForm::addFormPath(__DIR__ . '/forms');
                        $form->loadFile('item', false);
                }
                return true;
            }

    }
    return true;
}   

The item.xml stays the same.

BTW: I am using Joomla version 3.4.1 now.

Meissen answered 13/5, 2015 at 5:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.