0

我正在创建一个自定义字段来创建一个输入图像数组作为媒体类型。

如何带回类型为 media 的输入数组?

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" />
4

1 回答 1

0

有两个问题。第一个问题是您扩展核心 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_type http://docs.joomla.org/List_form_field_type http://docs.joomla.org/Creating_a_modal_form_field

于 2014-09-16T01:05:26.693 回答