Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 707
RAN Avatar asked Sep 14 '14 10:09

RAN


1 Answers

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.

like image 103
RAN Avatar answered Oct 29 '22 19:10

RAN