1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27:
28: 29: 30: 31: 32: 33: 34:
35: class Mage_Adminhtml_Block_System_Config_Form_Field
36: extends Mage_Adminhtml_Block_Abstract
37: implements Varien_Data_Form_Element_Renderer_Interface
38: {
39:
40: 41: 42: 43: 44: 45:
46: protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
47: {
48: return $element->getElementHtml();
49: }
50:
51: 52: 53: 54: 55: 56:
57: public function render(Varien_Data_Form_Element_Abstract $element)
58: {
59: $id = $element->getHtmlId();
60:
61: $html = '<td class="label"><label for="'.$id.'">'.$element->getLabel().'</label></td>';
62:
63:
64: $isMultiple = $element->getExtType()==='multiple';
65:
66:
67: $namePrefix = preg_replace('#\[value\](\[\])?$#', '', $element->getName());
68:
69: $options = $element->getValues();
70:
71: $addInheritCheckbox = false;
72: if ($element->getCanUseWebsiteValue()) {
73: $addInheritCheckbox = true;
74: $checkboxLabel = Mage::helper('adminhtml')->__('Use Website');
75: }
76: elseif ($element->getCanUseDefaultValue()) {
77: $addInheritCheckbox = true;
78: $checkboxLabel = Mage::helper('adminhtml')->__('Use Default');
79: }
80:
81: if ($addInheritCheckbox) {
82: $inherit = $element->getInherit()==1 ? 'checked="checked"' : '';
83: if ($inherit) {
84: $element->setDisabled(true);
85: }
86: }
87:
88: if ($element->getTooltip()) {
89: $html .= '<td class="value with-tooltip">';
90: $html .= $this->_getElementHtml($element);
91: $html .= '<div class="field-tooltip"><div>' . $element->getTooltip() . '</div></div>';
92: } else {
93: $html .= '<td class="value">';
94: $html .= $this->_getElementHtml($element);
95: };
96: if ($element->getComment()) {
97: $html.= '<p class="note"><span>'.$element->getComment().'</span></p>';
98: }
99: $html.= '</td>';
100:
101: if ($addInheritCheckbox) {
102:
103: $defText = $element->getDefaultValue();
104: if ($options) {
105: $defTextArr = array();
106: foreach ($options as $k=>$v) {
107: if ($isMultiple) {
108: if (is_array($v['value']) && in_array($k, $v['value'])) {
109: $defTextArr[] = $v['label'];
110: }
111: } elseif ($v['value']==$defText) {
112: $defTextArr[] = $v['label'];
113: break;
114: }
115: }
116: $defText = join(', ', $defTextArr);
117: }
118:
119:
120: $html.= '<td class="use-default">';
121:
122: $html.= '<input id="'.$id.'_inherit" name="'.$namePrefix.'[inherit]" type="checkbox" value="1" class="checkbox config-inherit" '.$inherit.' onclick="toggleValueElements(this, Element.previous(this.parentNode))" /> ';
123: $html.= '<label for="'.$id.'_inherit" class="inherit" title="'.htmlspecialchars($defText).'">'.$checkboxLabel.'</label>';
124: $html.= '</td>';
125: }
126:
127: $html.= '<td class="scope-label">';
128: if ($element->getScope()) {
129: $html .= $element->getScopeLabel();
130: }
131: $html.= '</td>';
132:
133: $html.= '<td class="">';
134: if ($element->getHint()) {
135: $html.= '<div class="hint" >';
136: $html.= '<div style="display: none;">' . $element->getHint() . '</div>';
137: $html.= '</div>';
138: }
139: $html.= '</td>';
140:
141: return $this->_decorateRowHtml($element, $html);
142: }
143:
144: 145: 146: 147: 148: 149: 150:
151: protected function _decorateRowHtml($element, $html)
152: {
153: return '<tr id="row_' . $element->getHtmlId() . '">' . $html . '</tr>';
154: }
155: }
156: