2016-01-13 104 views
0

我爲Joomla 3.x創建了一個模塊,我想要一個自定義參數。我檢查了joomla文檔上的Creating a custom form field type頁面,並且檢查了一個有自定義字段的第三方模塊,但是我無法使其工作。爲Joomla 3.x模塊創建自定義字段

也許我錯過了一步或做錯了什麼,但我無法弄清楚什麼。

這是我做的,到目前爲止:

在我添加的自定義字段集和現場像這樣的模塊XML文件:

<fielset name="TITLE" addfieldpath="/modules/mod_mymodule/admin"> 
    <field type="customfield" name="custom" /> 
</fieldset> 

比我創建了一個名爲customfield.php並在文件我有這樣的:

<?php 
defined('_JEXEC') or die; 
jimport('joomla.form.formfield'); 

class JFormFieldCustomfield extends JFormField { 
    protected $type = 'customfield'; 

    public function getInput(){ 
     $custom_form = '<div class="input-prepend input-append">'; 
     $custom_form .= '<div class="media-preview add-on"><span title="" class="hasTipPreview"><span class="icon-eye"></span></span></div>'; 
     $custom_form .= '<input type="text" id="jform_params_backgroundimage" class="input-small hasTipImgpath" readonly value="" aria-invalid="false" name="jform[params][backgroundimage]" />'; 
     $custom_form .= '<a rel="{handler: \'iframe\', size: {x: 800, y: 500}}" href="index.php?option=com_media&amp;view=images&amp;tmpl=component&amp;asset=com_modules&amp;author=&amp;fieldid=jform_params_backgroundimage&amp;folder=" title="'.JText::_('JSELECT').'" class="modal btn">'.JText::_('JSELECT').'</a>'; 
     $custom_form .= '<a onclick="jInsertFieldValue('', \'jform_params_backgroundimage\'); return false;" href="#" title="" class="btn hasTooltip" data-original-title="'.JText::_('JCLEAR').'"><span class="icon-remove"></span></a>'; 
     $custom_form .= '</div>'; 

     return $custom_form; 
    } 
} 
?> 

這是basicly媒體字段類型的副本,但這只是用於測試,很明顯,我就不需要自定義字段這一點。

該字段集顯示在管理員作爲選項卡,因爲它應該是,但該字段不。正如我在第三方模塊中看到的,我添加了addfilepath到<fields name="params" addfieldpath="/modules/mod_carousel/admin">,但仍然沒有任何結果。

我在想什麼或做錯了什麼?

回答

0

僅使用此代碼,請不要使用類

<?php 
defined('_JEXEC') or die; 
$custom_form = '<div class="input-prepend input-append">'; 
     $custom_form .= '<div class="media-preview add-on"><span title="" class="hasTipPreview"><span class="icon-eye"></span></span></div>'; 
     $custom_form .= '<input type="text" id="jform_params_backgroundimage" class="input-small hasTipImgpath" readonly value="" aria-invalid="false" name="jform[params][backgroundimage]" />'; 
     $custom_form .= '<a rel="{handler: \'iframe\', size: {x: 800, y: 500}}" href="index.php?option=com_media&amp;view=images&amp;tmpl=component&amp;asset=com_modules&amp;author=&amp;fieldid=jform_params_backgroundimage&amp;folder=" title="'.JText::_('JSELECT').'" class="modal btn">'.JText::_('JSELECT').'</a>'; 
     $custom_form .= '<a onclick="jInsertFieldValue('', \'jform_params_backgroundimage\'); return false;" href="#" title="" class="btn hasTooltip" data-original-title="'.JText::_('JCLEAR').'"><span class="icon-remove"></span></a>'; 
     $custom_form .= '</div>'; 

     echo $custom_form;