Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In order to do this, you need a custom renderer for the <code>file</code> input in your form. For this create the following class:</p> <pre><code>&lt;?php class {{Namespace}}_{{Module}}_Block_Adminhtml_{{Entity}}_Helper_File extends Varien_Data_Form_Element_Abstract{ public function __construct($data){ parent::__construct($data); $this-&gt;setType('file'); } public function getElementHtml(){ $html = ''; $this-&gt;addClass('input-file'); $html.= parent::getElementHtml(); if ($this-&gt;getValue()) { $url = $this-&gt;_getUrl(); if( !preg_match("/^http\:\/\/|https\:\/\//", $url) ) { $url = Mage::getBaseUrl('media').'{{entity}}'.'/'.'file' . $url; //replace this with the path to the file if you upload it somewhere else } $html .= '&lt;br /&gt;&lt;a href="'.$url.'"&gt;'.$this-&gt;_getUrl().'&lt;/a&gt; '; } $html.= $this-&gt;_getDeleteCheckbox(); return $html; } protected function _getDeleteCheckbox(){ $html = ''; if ($this-&gt;getValue()) { $label = Mage::helper('{{module}}')-&gt;__('Delete File'); $html .= '&lt;span class="delete-image"&gt;'; $html .= '&lt;input type="checkbox" name="'.parent::getName().'[delete]" value="1" class="checkbox" id="'.$this-&gt;getHtmlId().'_delete"'.($this-&gt;getDisabled() ? ' disabled="disabled"': '').'/&gt;'; $html .= '&lt;label for="'.$this-&gt;getHtmlId().'_delete"'.($this-&gt;getDisabled() ? ' class="disabled"' : '').'&gt; '.$label.'&lt;/label&gt;'; $html .= $this-&gt;_getHiddenInput(); $html .= '&lt;/span&gt;'; } return $html; } protected function _getHiddenInput(){ return '&lt;input type="hidden" name="'.parent::getName().'[value]" value="'.$this-&gt;getValue().'" /&gt;'; } protected function _getUrl(){ return $this-&gt;getValue(); } public function getName(){ return $this-&gt;getData('name'); } } </code></pre> <p>Then you need to tell your for to use this for the file inputs. So in your edit form tab, add this right after defining the fiedlset:</p> <pre><code>$fieldset-&gt;addType('file', Mage::getConfig()-&gt;getBlockClassName('{{module}}/adminhtml_{{entity}}_helper_file')); </code></pre> <p>Replace <code>{{Namespace}}</code>, {{Module}} and <code>{{Entity}}</code> with the appropriate values keeping the case.<br> <code>Namespace</code> is the namespace of your module (D'uh), <code>Module</code> is the name of your module (D'uh again), and Entity is what you are managing. Can be <code>Article</code>, <code>News</code>, <code>Files</code>....<br> <strong>[EDIT]</strong><br> You can build your module using <a href="http://www.magentocommerce.com/magento-connect/ultimate-modulecreator-8949.html">this module creator</a>. It takes care of these kind of issues.<br> Note: I hope this is not considered self promotion. The extension is free and I get no financial benefits out of it.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload