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: abstract class Mage_Eav_Block_Adminhtml_Attribute_Edit_Main_Abstract extends Mage_Adminhtml_Block_Widget_Form
36: {
37: protected $_attribute = null;
38:
39: public function setAttributeObject($attribute)
40: {
41: $this->_attribute = $attribute;
42: return $this;
43: }
44:
45: public function getAttributeObject()
46: {
47: if (null === $this->_attribute) {
48: return Mage::registry('entity_attribute');
49: }
50: return $this->_attribute;
51: }
52:
53: 54: 55: 56: 57:
58: protected function _prepareForm()
59: {
60: $attributeObject = $this->getAttributeObject();
61:
62: $form = new Varien_Data_Form(array(
63: 'id' => 'edit_form',
64: 'action' => $this->getData('action'),
65: 'method' => 'post'
66: ));
67:
68: $fieldset = $form->addFieldset('base_fieldset',
69: array('legend'=>Mage::helper('eav')->__('Attribute Properties'))
70: );
71: if ($attributeObject->getAttributeId()) {
72: $fieldset->addField('attribute_id', 'hidden', array(
73: 'name' => 'attribute_id',
74: ));
75: }
76:
77: $this->_addElementTypes($fieldset);
78:
79: $yesno = Mage::getModel('adminhtml/system_config_source_yesno')->toOptionArray();
80:
81: $validateClass = sprintf('validate-code validate-length maximum-length-%d',
82: Mage_Eav_Model_Entity_Attribute::ATTRIBUTE_CODE_MAX_LENGTH);
83: $fieldset->addField('attribute_code', 'text', array(
84: 'name' => 'attribute_code',
85: 'label' => Mage::helper('eav')->__('Attribute Code'),
86: 'title' => Mage::helper('eav')->__('Attribute Code'),
87: 'note' => Mage::helper('eav')->__('For internal use. Must be unique with no spaces. Maximum length of attribute code must be less then %s symbols', Mage_Eav_Model_Entity_Attribute::ATTRIBUTE_CODE_MAX_LENGTH),
88: 'class' => $validateClass,
89: 'required' => true,
90: ));
91:
92: $inputTypes = Mage::getModel('eav/adminhtml_system_config_source_inputtype')->toOptionArray();
93:
94: $fieldset->addField('frontend_input', 'select', array(
95: 'name' => 'frontend_input',
96: 'label' => Mage::helper('eav')->__('Catalog Input Type for Store Owner'),
97: 'title' => Mage::helper('eav')->__('Catalog Input Type for Store Owner'),
98: 'value' => 'text',
99: 'values'=> $inputTypes
100: ));
101:
102: $fieldset->addField('default_value_text', 'text', array(
103: 'name' => 'default_value_text',
104: 'label' => Mage::helper('eav')->__('Default Value'),
105: 'title' => Mage::helper('eav')->__('Default Value'),
106: 'value' => $attributeObject->getDefaultValue(),
107: ));
108:
109: $fieldset->addField('default_value_yesno', 'select', array(
110: 'name' => 'default_value_yesno',
111: 'label' => Mage::helper('eav')->__('Default Value'),
112: 'title' => Mage::helper('eav')->__('Default Value'),
113: 'values' => $yesno,
114: 'value' => $attributeObject->getDefaultValue(),
115: ));
116:
117: $dateFormatIso = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
118: $fieldset->addField('default_value_date', 'date', array(
119: 'name' => 'default_value_date',
120: 'label' => Mage::helper('eav')->__('Default Value'),
121: 'title' => Mage::helper('eav')->__('Default Value'),
122: 'image' => $this->getSkinUrl('images/grid-cal.gif'),
123: 'value' => $attributeObject->getDefaultValue(),
124: 'format' => $dateFormatIso
125: ));
126:
127: $fieldset->addField('default_value_textarea', 'textarea', array(
128: 'name' => 'default_value_textarea',
129: 'label' => Mage::helper('eav')->__('Default Value'),
130: 'title' => Mage::helper('eav')->__('Default Value'),
131: 'value' => $attributeObject->getDefaultValue(),
132: ));
133:
134: $fieldset->addField('is_unique', 'select', array(
135: 'name' => 'is_unique',
136: 'label' => Mage::helper('eav')->__('Unique Value'),
137: 'title' => Mage::helper('eav')->__('Unique Value (not shared with other products)'),
138: 'note' => Mage::helper('eav')->__('Not shared with other products'),
139: 'values' => $yesno,
140: ));
141:
142: $fieldset->addField('is_required', 'select', array(
143: 'name' => 'is_required',
144: 'label' => Mage::helper('eav')->__('Values Required'),
145: 'title' => Mage::helper('eav')->__('Values Required'),
146: 'values' => $yesno,
147: ));
148:
149: $fieldset->addField('frontend_class', 'select', array(
150: 'name' => 'frontend_class',
151: 'label' => Mage::helper('eav')->__('Input Validation for Store Owner'),
152: 'title' => Mage::helper('eav')->__('Input Validation for Store Owner'),
153: 'values'=> Mage::helper('eav')->getFrontendClasses($attributeObject->getEntityType()->getEntityTypeCode())
154: ));
155:
156: if ($attributeObject->getId()) {
157: $form->getElement('attribute_code')->setDisabled(1);
158: $form->getElement('frontend_input')->setDisabled(1);
159: if (!$attributeObject->getIsUserDefined()) {
160: $form->getElement('is_unique')->setDisabled(1);
161: }
162: }
163:
164: $this->setForm($form);
165:
166: return parent::_prepareForm();
167: }
168:
169: 170: 171: 172: 173:
174: protected function _initFormValues()
175: {
176: Mage::dispatchEvent('adminhtml_block_eav_attribute_edit_form_init', array('form' => $this->getForm()));
177: $this->getForm()
178: ->addValues($this->getAttributeObject()->getData());
179: return parent::_initFormValues();
180: }
181:
182: 183: 184: 185: 186:
187: protected function _beforeToHtml()
188: {
189: parent::_beforeToHtml();
190: $attributeObject = $this->getAttributeObject();
191: if ($attributeObject->getId()) {
192: $form = $this->getForm();
193: $disableAttributeFields = Mage::helper('eav')
194: ->getAttributeLockedFields($attributeObject->getEntityType()->getEntityTypeCode());
195: if (isset($disableAttributeFields[$attributeObject->getAttributeCode()])) {
196: foreach ($disableAttributeFields[$attributeObject->getAttributeCode()] as $field) {
197: if ($elm = $form->getElement($field)) {
198: $elm->setDisabled(1);
199: $elm->setReadonly(1);
200: }
201: }
202: }
203: }
204: return $this;
205: }
206:
207: 208: 209: 210: 211: 212: 213:
214: protected function _afterToHtml($html)
215: {
216: $jsScripts = $this->getLayout()
217: ->createBlock('eav/adminhtml_attribute_edit_js')->toHtml();
218: return $html.$jsScripts;
219: }
220:
221: }
222: