/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Form.php

https://bitbucket.org/jokusafet/magento2 · PHP · 132 lines · 68 code · 10 blank · 54 comment · 4 complexity · 391e641f08997aed6def5a470d8762d6 MD5 · raw file

  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magentocommerce.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magentocommerce.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_Widget
  23. * @copyright Copyright (c) 2012 X.commerce, Inc. (http://www.magentocommerce.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /**
  27. * WYSIWYG widget plugin form
  28. *
  29. * @category Mage
  30. * @package Mage_Widget
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Mage_Widget_Block_Adminhtml_Widget_Form extends Mage_Adminhtml_Block_Widget_Form
  34. {
  35. /**
  36. * Form with widget to select
  37. */
  38. protected function _prepareForm()
  39. {
  40. $form = new Varien_Data_Form();
  41. $fieldset = $form->addFieldset('base_fieldset', array(
  42. 'legend' => $this->helper('Mage_Widget_Helper_Data')->__('Widget')
  43. ));
  44. $select = $fieldset->addField('select_widget_type', 'select', array(
  45. 'label' => $this->helper('Mage_Widget_Helper_Data')->__('Widget Type'),
  46. 'title' => $this->helper('Mage_Widget_Helper_Data')->__('Widget Type'),
  47. 'name' => 'widget_type',
  48. 'required' => true,
  49. 'options' => $this->_getWidgetSelectOptions(),
  50. 'after_element_html' => $this->_getWidgetSelectAfterHtml(),
  51. ));
  52. $form->setUseContainer(true);
  53. $form->setId('widget_options_form');
  54. $form->setMethod('post');
  55. $form->setAction($this->getUrl('*/*/buildWidget'));
  56. $this->setForm($form);
  57. }
  58. /**
  59. * Prepare options for widgets HTML select
  60. *
  61. * @return array
  62. */
  63. protected function _getWidgetSelectOptions()
  64. {
  65. foreach ($this->_getAvailableWidgets(true) as $data) {
  66. $options[$data['type']] = $data['name'];
  67. }
  68. return $options;
  69. }
  70. /**
  71. * Prepare widgets select after element HTML
  72. *
  73. * @return string
  74. */
  75. protected function _getWidgetSelectAfterHtml()
  76. {
  77. $html = '<p class="nm"><small></small></p>';
  78. $i = 0;
  79. foreach ($this->_getAvailableWidgets(true) as $data) {
  80. $html .= sprintf('<div id="widget-description-%s" class="no-display">%s</div>', $i, $data['description']);
  81. $i++;
  82. }
  83. return $html;
  84. }
  85. /**
  86. * Return array of available widgets based on configuration
  87. *
  88. * @return array
  89. */
  90. protected function _getAvailableWidgets($withEmptyElement = false)
  91. {
  92. if (!$this->hasData('available_widgets')) {
  93. $result = array();
  94. $allWidgets = Mage::getModel('Mage_Widget_Model_Widget')->getWidgetsArray();
  95. $skipped = $this->_getSkippedWidgets();
  96. foreach ($allWidgets as $widget) {
  97. if (is_array($skipped) && in_array($widget['type'], $skipped)) {
  98. continue;
  99. }
  100. $result[] = $widget;
  101. }
  102. if ($withEmptyElement) {
  103. array_unshift($result, array(
  104. 'type' => '',
  105. 'name' => $this->helper('Mage_Adminhtml_Helper_Data')->__('-- Please Select --'),
  106. 'description' => '',
  107. ));
  108. }
  109. $this->setData('available_widgets', $result);
  110. }
  111. return $this->_getData('available_widgets');
  112. }
  113. /**
  114. * Return array of widgets disabled for selection
  115. *
  116. * @return array
  117. */
  118. protected function _getSkippedWidgets()
  119. {
  120. return Mage::registry('skip_widgets');
  121. }
  122. }