我正在创建一个自定义字段,以创建一个作为媒体类型的输入图像数组。
如何使用类型媒体恢复输入数组?
class JFormFieldimglist extends JFormField {
//The field class must know its own type through the variable $type.
protected $type = 'imglist';
public function getLabel() {
return "List Image";
}
public function getInput() {
for ($i = 1; $i <= 10; $i++) {
$images.= '<input type="text" value="'.$this->value[$i].'" name="'.$this->name.'['.$i.']" />';
}
return $images;
}
}
从xml我使用这个
<field name = "myimage" type = "media" directory = "stories" />
有两个问题。第一个问题是扩展核心JFormField类。第二个问题是媒体字段类型实际上是一个模态形式字段。这是一种特殊的字段,用于在模式窗口中呈现更复杂的界面供用户选择。例如,当您为菜单类型的单个文章选择一篇文章,或单击所见即所得编辑器下方的"图像"按钮时。
我的猜测是,你想从一个特定的文件夹中提取一个图像列表,供用户从下拉列表中选择。请注意,在下面的示例中,我完全省略了getLabel()和getInput()方法,并添加了getOptions()。原因是通过扩展JFormFieldList类,这些方法已经构建出来,不需要特殊需求之外的方法。您只需重写getOptions()方法,就可以为核心类提供您希望在字段中显示的选项列表。
jimport('joomla.form.helper');
JFormHelper::loadFieldClass('list');
class JFormFieldimglist extends JFormFieldList {
//The field class must know its own type through the variable $type.
protected $type = 'imglist';
public function getOptions() {
// build out your options array
// You should format as array, with full path as key and
// human readable as value
$options = array('/images/flowers/tulip.png' => 'Tulip');
return $options;
}
}
以下是我的帖子的一些扩展链接。
http://docs.joomla.org/Creating_a_custom_form_field_typehttp://docs.joomla.org/List_form_field_typehttp://docs.joomla.org/Creating_a_modal_form_field