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_Widget_Block_Adminhtml_Widget_Instance_Edit_Chooser_Layout
35: extends Mage_Adminhtml_Block_Widget
36: {
37: protected $_layoutHandles = array();
38:
39: 40: 41: 42: 43:
44: protected $_layoutHandlePatterns = array(
45: '^default$',
46: '^catalog_category_*',
47: '^catalog_product_*',
48: '^PRODUCT_*'
49: );
50:
51: 52: 53:
54: protected function _construct()
55: {
56: parent::_construct();
57: }
58:
59: 60: 61: 62: 63: 64:
65: public function addLayoutHandlePattern($pattern)
66: {
67: $this->_layoutHandlePatterns[] = $pattern;
68: return $this;
69: }
70:
71: 72: 73: 74: 75:
76: public function getLayoutHandlePatterns()
77: {
78: return $this->_layoutHandlePatterns;
79: }
80:
81: 82: 83: 84: 85:
86: public function getArea()
87: {
88: if (!$this->_getData('area')) {
89: return Mage_Core_Model_Design_Package::DEFAULT_AREA;
90: }
91: return $this->_getData('area');
92: }
93:
94: 95: 96: 97: 98:
99: public function getPackage()
100: {
101: if (!$this->_getData('package')) {
102: return Mage_Core_Model_Design_Package::DEFAULT_PACKAGE;
103: }
104: return $this->_getData('package');
105: }
106:
107: 108: 109: 110: 111:
112: public function getTheme()
113: {
114: if (!$this->_getData('theme')) {
115: return Mage_Core_Model_Design_Package::DEFAULT_THEME;
116: }
117: return $this->_getData('theme');
118: }
119:
120: 121: 122: 123: 124:
125: protected function _toHtml()
126: {
127: $selectBlock = $this->getLayout()->createBlock('core/html_select')
128: ->setName($this->getSelectName())
129: ->setId('layout_handle')
130: ->setClass('required-entry select')
131: ->setExtraParams("onchange=\"WidgetInstance.loadSelectBoxByType(\'block_reference\', " .
132: "this.up(\'div.pages\'), this.value)\"")
133: ->setOptions($this->getLayoutHandles(
134: $this->getArea(),
135: $this->getPackage(),
136: $this->getTheme()));
137: return parent::_toHtml().$selectBlock->toHtml();
138: }
139:
140: 141: 142: 143: 144: 145: 146: 147:
148: public function getLayoutHandles($area, $package, $theme)
149: {
150: if (empty($this->_layoutHandles)) {
151:
152: $update = Mage::getModel('core/layout')->getUpdate();
153: $this->_layoutHandles[''] = Mage::helper('widget')->__('-- Please Select --');
154: $this->_collectLayoutHandles($update->getFileLayoutUpdatesXml($area, $package, $theme));
155: }
156: return $this->_layoutHandles;
157: }
158:
159: 160: 161: 162: 163:
164: protected function _collectLayoutHandles($layoutHandles)
165: {
166: if ($layoutHandlesArr = $layoutHandles->xpath('/*/*/label/..')) {
167: foreach ($layoutHandlesArr as $node) {
168: if ($this->_filterLayoutHandle($node->getName())) {
169: $helper = Mage::helper(Mage_Core_Model_Layout::findTranslationModuleName($node));
170: $this->_layoutHandles[$node->getName()] = $this->helper('core')->jsQuoteEscape(
171: $helper->__((string)$node->label)
172: );
173: }
174: }
175: asort($this->_layoutHandles, SORT_STRING);
176: }
177: }
178:
179: 180: 181: 182: 183: 184:
185: protected function _filterLayoutHandle($layoutHandle)
186: {
187: $wildCard = '/('.implode(')|(', $this->getLayoutHandlePatterns()).')/';
188: if (preg_match($wildCard, $layoutHandle)) {
189: return false;
190: }
191: return true;
192: }
193: }
194: