Joomla 3.3 - 通过插件向所有菜单项添加自定义字段 - 未保存参数

时间:2014-09-14 10:21:41

标签: php xml plugins joomla joomla3.0

将自定义字段添加到com_menus - item视图时出现问题。

教程: (见:http://docs.joomla.org/Adding_custom_fields_to_core_components_using_a_plugin

本教程效果很好(com_contact),但是当我想要覆盖菜单项视图时:参数未被保存!!!

以下是我用来确定组件的代码和添加自定义表单的视图。

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;

    }   
}

这是要加载的item.xml(/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>

当我创建或编辑菜单项时,表单正在正确呈现,但是当我点击&#34; Save&#34;时,没有保存这些值。

感谢。

1 个答案:

答案 0 :(得分:4)

我通过删除If块中的$ view =='item'条件解决了这个问题。

最后看起来像这样:

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;
}   

item.xml保持不变。

BTW:我现在正在使用Joomla 3.4.1版。