繁体   English   中英

核心组件的自定义表格字段

[英]Custom formfield for core component

我正在为Joomla 3.2编写一个小插件,该插件应该扩展核心组件(com_content),因此在创建文章时,它还会在后端显示自定义表单字段。

我遵循了docs指示 ,但是不幸的是,它根本无法解决 表单字段按应有的方式显示在后端,但是当我输入内容并单击“保存”时,值将不会存储在数据库中。

test123.php

    <?php
    defined ( '_JEXEC' ) or die ( 'Restricted access' );

    class plgContentTest123 extends JPlugin {

            protected $autoloadLanguage = true;

            function onContentPrepareForm($form, $data) {
                    $app = JFactory::getApplication();
                    $option = $app->input->get('option');

                    switch($option) {
                            case 'com_content':
                            if ($app->isAdmin()) {
                                    JForm::addFormPath(__DIR__ . '/forms');
                                    $form->loadFile('content', false);
                            }
                            return true;
                    }
                    return true;
            }
    }
    ?>

表格/content.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <form>
            <fields name="params" >
                    <fieldset name="params" >
                            <field
                                    name="test123"
                                    type="text"
                                    label="Test Field"
                                    />
                            <field
                                    name="test234"
                                    type="text"
                                    label="Another one"
                                    filter="email"
                            />
                    </fieldset>
            </fields>
    </form>

但是,我可以用XML文件替换以前存在的表单域-这些值已正确存储。 (此外,我注意到, Jform::loadFile$reset参数( 请参阅docs )没有任何作用。无论是true还是false ,都会始终替换formfields。)

我完全不知道这里发生了什么……!? 那有人吗

我找到了解决问题的办法。 仅供将来参考:

本教程不适用于com_content的原因是,数据库中的__content没有字段“ params”(与本教程中使用的__contact_details相比)。

因此,要么您必须更改表并添加一列。 但是,有一个更好的解决方案:由于字段集中的所有参数都以JSON编码的字符串存储在数据库中,因此您可以简单地使用自定义参数连接到现有的字段集中:

<?xml version="1.0" encoding="UTF-8"?>
<form>
        <fields name="urls" >
                <fieldset name="urls" >
                        <field
                                name="test123"
                                type="text"
                                label="Test Field"
                                />
                        <field
                                name="test234"
                                type="text"
                                label="Another one"
                                filter="email"
                        />
                </fieldset>
        </fields>
</form>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM