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_Widget_Block_Adminhtml_Widget_Form extends Mage_Adminhtml_Block_Widget_Form
36: {
37: 38: 39:
40: protected function _prepareForm()
41: {
42: $form = new Varien_Data_Form();
43:
44: $fieldset = $form->addFieldset('base_fieldset', array(
45: 'legend' => $this->helper('widget')->__('Widget')
46: ));
47:
48: $select = $fieldset->addField('select_widget_type', 'select', array(
49: 'label' => $this->helper('widget')->__('Widget Type'),
50: 'title' => $this->helper('widget')->__('Widget Type'),
51: 'name' => 'widget_type',
52: 'required' => true,
53: 'options' => $this->_getWidgetSelectOptions(),
54: 'after_element_html' => $this->_getWidgetSelectAfterHtml(),
55: ));
56:
57: $form->setUseContainer(true);
58: $form->setId('widget_options_form');
59: $form->setMethod('post');
60: $form->setAction($this->getUrl('*/*/buildWidget'));
61: $this->setForm($form);
62: }
63:
64: 65: 66: 67: 68:
69: protected function _getWidgetSelectOptions()
70: {
71: foreach ($this->_getAvailableWidgets(true) as $data) {
72: $options[$data['type']] = $data['name'];
73: }
74: return $options;
75: }
76:
77: 78: 79: 80: 81:
82: protected function _getWidgetSelectAfterHtml()
83: {
84: $html = '<p class="nm"><small></small></p>';
85: $i = 0;
86: foreach ($this->_getAvailableWidgets(true) as $data) {
87: $html .= sprintf('<div id="widget-description-%s" class="no-display">%s</div>', $i, $data['description']);
88: $i++;
89: }
90: return $html;
91: }
92:
93: 94: 95: 96: 97:
98: protected function _getAvailableWidgets($withEmptyElement = false)
99: {
100: if (!$this->hasData('available_widgets')) {
101: $result = array();
102: $allWidgets = Mage::getModel('widget/widget')->getWidgetsArray();
103: $skipped = $this->_getSkippedWidgets();
104: foreach ($allWidgets as $widget) {
105: if (is_array($skipped) && in_array($widget['type'], $skipped)) {
106: continue;
107: }
108: $result[] = $widget;
109: }
110: if ($withEmptyElement) {
111: array_unshift($result, array(
112: 'type' => '',
113: 'name' => $this->helper('adminhtml')->__('-- Please Select --'),
114: 'description' => '',
115: ));
116: }
117: $this->setData('available_widgets', $result);
118: }
119:
120: return $this->_getData('available_widgets');
121: }
122:
123: 124: 125: 126: 127:
128: protected function _getSkippedWidgets()
129: {
130: return Mage::registry('skip_widgets');
131: }
132: }
133: