【发布时间】:2014-04-07 15:56:37
【问题描述】:
我正在为 Joomla 3.2 编写一个小插件,它应该扩展一个核心组件 (com_content),因此在创建文章时它会在后端额外显示自定义表单字段。
我关注了instructions from the 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;
}
}
?>
forms/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 (See docs) 的$reset 参数没有任何作用。不管是true 还是false,表单域总是被替换。)
我完全不知道这里发生了什么……!?有人呢?
【问题讨论】: