Skip to content

Instantly share code, notes, and snippets.

@ianitsky
Created August 9, 2018 19:06
Show Gist options
  • Save ianitsky/852d4d51bd559612235e8c0c7fbc8e76 to your computer and use it in GitHub Desktop.
Save ianitsky/852d4d51bd559612235e8c0c7fbc8e76 to your computer and use it in GitHub Desktop.
Magento - Add textarea to admin system config tables
<?php
/**
* Use
*/
class Module_Adminhtml_Block_Config_Data extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract
{
protected $_textareaRenderer;
public function __construct()
{
$this->setTemplate('system/config/form/field/array.phtml');
parent::__construct();
}
public function _prepareToRender()
{
$this->addColumn('textarea', array(
'label' => $this->__('Textarea'),
'renderer' => $this->_getTextareaRenderer()
));
$this->_addAfter = false;
$this->_addButtonLabel = $this->__('Add');
}
protected function _getTextareaRenderer()
{
if (!$this->_textareaRenderer) {
$this->_textareaRenderer = $this->getLayout()->createBlock(
'module_adminhtml/system_config_form_field_textarea', ''
);
}
return $this->_textareaRenderer;
}
}
<?php
class Module_Adminhtml_Block_System_Config_Form_Field_Textarea extends Mage_Core_Block_Template
{
public function _toHtml()
{
$inputName = $this->getInputName();
$columnName = $this->getColumnName();
$column = $this->getColumn();
return '<textarea type="text" name="' . $inputName . '" value="#{' . $columnName . '}" ' .
($column['size'] ? 'size="' . $column['size'] . '"' : '') . ' class="' .
(isset($column['class']) ? $column['class'] : 'input-text') . '"'.
(isset($column['style']) ? ' style="'.$column['style'] . '"' : '') . '>#{' . $columnName . '}</textarea>';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment