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: class Mage_Adminhtml_Block_Catalog_Category_Tab_General extends Mage_Adminhtml_Block_Catalog_Form
35: {
36:
37: protected $_category;
38:
39: public function __construct()
40: {
41: parent::__construct();
42: $this->setShowGlobalIcon(true);
43: }
44:
45: public function getCategory()
46: {
47: if (!$this->_category) {
48: $this->_category = Mage::registry('category');
49: }
50: return $this->_category;
51: }
52:
53: public function _prepareLayout()
54: {
55: parent::_prepareLayout();
56: $form = new Varien_Data_Form();
57: $form->setHtmlIdPrefix('_general');
58: $form->setDataObject($this->getCategory());
59:
60: $fieldset = $form->addFieldset('base_fieldset', array('legend'=>Mage::helper('catalog')->__('General Information')));
61:
62: if (!$this->getCategory()->getId()) {
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73: $parentId = $this->getRequest()->getParam('parent');
74: if (!$parentId) {
75: $parentId = Mage_Catalog_Model_Category::TREE_ROOT_ID;
76: }
77: $fieldset->addField('path', 'hidden', array(
78: 'name' => 'path',
79: 'value' => $parentId
80: ));
81: } else {
82: $fieldset->addField('id', 'hidden', array(
83: 'name' => 'id',
84: 'value' => $this->getCategory()->getId()
85: ));
86: $fieldset->addField('path', 'hidden', array(
87: 'name' => 'path',
88: 'value' => $this->getCategory()->getPath()
89: ));
90: }
91:
92: $this->_setFieldset($this->getCategory()->getAttributes(true), $fieldset);
93:
94: if ($this->getCategory()->getId()) {
95: if ($this->getCategory()->getLevel() == 1) {
96: $fieldset->removeField('url_key');
97: $fieldset->addField('url_key', 'hidden', array(
98: 'name' => 'url_key',
99: 'value' => $this->getCategory()->getUrlKey()
100: ));
101: }
102: }
103:
104: $form->addValues($this->getCategory()->getData());
105:
106: $form->setFieldNameSuffix('general');
107: $this->setForm($form);
108: }
109:
110: protected function _getAdditionalElementTypes()
111: {
112: return array(
113: 'image' => Mage::getConfig()->getBlockClassName('adminhtml/catalog_category_helper_image')
114: );
115: }
116:
117: protected function _getParentCategoryOptions($node=null, &$options=array())
118: {
119: if (is_null($node)) {
120: $node = $this->getRoot();
121: }
122:
123: if ($node) {
124: $options[] = array(
125: 'value' => $node->getPathId(),
126: 'label' => str_repeat(' ', max(0, 3*($node->getLevel()))) . $this->htmlEscape($node->getName()),
127: );
128:
129: foreach ($node->getChildren() as $child) {
130: $this->_getParentCategoryOptions($child, $options);
131: }
132: }
133: return $options;
134: }
135:
136: }
137:
138: