Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Widget_Adminhtml_Widget_InstanceController
  • Mage_Widget_Adminhtml_WidgetController
  • Mage_Widget_Block_Adminhtml_Widget_Form
  • Mage_Widget_Block_Adminhtml_Widget_Instance
  • Mage_Widget_Block_Adminhtml_Widget_Instance_Edit
  • Mage_Widget_Block_Adminhtml_Widget_Instance_Edit_Chooser_Block
  • Mage_Widget_Block_Adminhtml_Widget_Instance_Edit_Chooser_Layout
  • Mage_Widget_Block_Adminhtml_Widget_Instance_Edit_Chooser_Template
  • Mage_Widget_Block_Adminhtml_Widget_Instance_Edit_Form
  • Mage_Widget_Block_Adminhtml_Widget_Instance_Edit_Tab_Main
  • Mage_Widget_Block_Adminhtml_Widget_Instance_Edit_Tab_Main_Layout
  • Mage_Widget_Block_Adminhtml_Widget_Instance_Edit_Tab_Properties
  • Mage_Widget_Block_Adminhtml_Widget_Instance_Edit_Tab_Settings
  • Mage_Widget_Block_Adminhtml_Widget_Instance_Edit_Tabs
  • Mage_Widget_Block_Adminhtml_Widget_Instance_Grid
  • Mage_Widget_Block_Adminhtml_Widget_Options
  • Mage_Widget_Helper_Data
  • Mage_Widget_Model_Mysql4_Widget
  • Mage_Widget_Model_Mysql4_Widget_Instance
  • Mage_Widget_Model_Mysql4_Widget_Instance_Collection
  • Mage_Widget_Model_Observer
  • Mage_Widget_Model_Resource_Widget
  • Mage_Widget_Model_Resource_Widget_Instance
  • Mage_Widget_Model_Resource_Widget_Instance_Collection
  • Mage_Widget_Model_Template_Filter
  • Mage_Widget_Model_Widget
  • Mage_Widget_Model_Widget_Config
  • Mage_Widget_Model_Widget_Instance

Interfaces

  • Mage_Widget_Block_Interface
  • Overview
  • Package
  • Class
  • Tree
  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 Magento Inc. (http://www.magentocommerce.com)
 24:  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 25:  */
 26: 
 27: /**
 28:  * WYSIWYG widget options form
 29:  *
 30:  * @category   Mage
 31:  * @package    Mage_Widget
 32:  * @author     Magento Core Team <core@magentocommerce.com>
 33:  */
 34: 
 35: class Mage_Widget_Block_Adminhtml_Widget_Options extends Mage_Adminhtml_Block_Widget_Form
 36: {
 37:     /**
 38:      * Element type used by default if configuration is omitted
 39:      * @var string
 40:      */
 41:     protected $_defaultElementType = 'text';
 42: 
 43:     /**
 44:      * Translation helper instance, defined by the widget type declaration root config node
 45:      * @var Mage_Core_Helper_Abstract
 46:      */
 47:     protected $_translationHelper = null;
 48: 
 49:     /**
 50:      * Prepare Widget Options Form and values according to specified type
 51:      *
 52:      * widget_type must be set in data before
 53:      * widget_values may be set before to render element values
 54:      */
 55:     protected function _prepareForm()
 56:     {
 57:         $this->getForm()->setUseContainer(false);
 58:         $this->addFields();
 59:         return $this;
 60:     }
 61: 
 62:     /**
 63:      * Form getter/instantiation
 64:      *
 65:      * @return Varien_Data_Form
 66:      */
 67:     public function getForm()
 68:     {
 69:         if ($this->_form instanceof Varien_Data_Form) {
 70:             return $this->_form;
 71:         }
 72:         $form = new Varien_Data_Form();
 73:         $this->setForm($form);
 74:         return $form;
 75:     }
 76: 
 77:     /**
 78:      * Fieldset getter/instantiation
 79:      *
 80:      * @return Varien_Data_Form_Element_Fieldset
 81:      */
 82:     public function getMainFieldset()
 83:     {
 84:         if ($this->_getData('main_fieldset') instanceof Varien_Data_Form_Element_Fieldset) {
 85:             return $this->_getData('main_fieldset');
 86:         }
 87:         $mainFieldsetHtmlId = 'options_fieldset' . md5($this->getWidgetType());
 88:         $this->setMainFieldsetHtmlId($mainFieldsetHtmlId);
 89:         $fieldset = $this->getForm()->addFieldset($mainFieldsetHtmlId, array(
 90:             'legend'    => $this->helper('widget')->__('Widget Options'),
 91:             'class'     => 'fieldset-wide',
 92:         ));
 93:         $this->setData('main_fieldset', $fieldset);
 94: 
 95:         // add dependence javascript block
 96:         $block = $this->getLayout()->createBlock('adminhtml/widget_form_element_dependence');
 97:         $this->setChild('form_after', $block);
 98: 
 99:         return $fieldset;
100:     }
101: 
102:     /**
103:      * Add fields to main fieldset based on specified widget type
104:      *
105:      * @return Mage_Adminhtml_Block_Widget_Form
106:      */
107:     public function addFields()
108:     {
109:         // get configuration node and translation helper
110:         if (!$this->getWidgetType()) {
111:             Mage::throwException($this->__('Widget Type is not specified'));
112:         }
113:         $config = Mage::getSingleton('widget/widget')->getConfigAsObject($this->getWidgetType());
114:         if (!$config->getParameters()) {
115:             return $this;
116:         }
117:         $module = $config->getModule();
118:         $this->_translationHelper = Mage::helper($module ? $module : 'widget');
119:         foreach ($config->getParameters() as $parameter) {
120:             $this->_addField($parameter);
121:         }
122: 
123:         return $this;
124:     }
125: 
126:     /**
127:      * Add field to Options form based on parameter configuration
128:      *
129:      * @param Varien_Object $parameter
130:      * @return Varien_Data_Form_Element_Abstract
131:      */
132:     protected function _addField($parameter)
133:     {
134:         $form = $this->getForm();
135:         $fieldset = $this->getMainFieldset(); //$form->getElement('options_fieldset');
136: 
137:         // prepare element data with values (either from request of from default values)
138:         $fieldName = $parameter->getKey();
139:         $data = array(
140:             'name'      => $form->addSuffixToName($fieldName, 'parameters'),
141:             'label'     => $this->_translationHelper->__($parameter->getLabel()),
142:             'required'  => $parameter->getRequired(),
143:             'class'     => 'widget-option',
144:             'note'      => $this->_translationHelper->__($parameter->getDescription()),
145:         );
146: 
147:         if ($values = $this->getWidgetValues()) {
148:             $data['value'] = (isset($values[$fieldName]) ? $values[$fieldName] : '');
149:         }
150:         else {
151:             $data['value'] = $parameter->getValue();
152:             //prepare unique id value
153:             if ($fieldName == 'unique_id' && $data['value'] == '') {
154:                 $data['value'] = md5(microtime(1));
155:             }
156:         }
157: 
158:         // prepare element dropdown values
159:         if ($values  = $parameter->getValues()) {
160:             // dropdown options are specified in configuration
161:             $data['values'] = array();
162:             foreach ($values as $option) {
163:                 $data['values'][] = array(
164:                     'label' => $this->_translationHelper->__($option['label']),
165:                     'value' => $option['value']
166:                 );
167:             }
168:         }
169:         // otherwise, a source model is specified
170:         elseif ($sourceModel = $parameter->getSourceModel()) {
171:             $data['values'] = Mage::getModel($sourceModel)->toOptionArray();
172:         }
173: 
174:         // prepare field type or renderer
175:         $fieldRenderer = null;
176:         $fieldType = $parameter->getType();
177:         // hidden element
178:         if (!$parameter->getVisible()) {
179:             $fieldType = 'hidden';
180:         }
181:         // just an element renderer
182:         elseif (false !== strpos($fieldType, '/')) {
183:             $fieldRenderer = $this->getLayout()->createBlock($fieldType);
184:             $fieldType = $this->_defaultElementType;
185:         }
186: 
187:         // instantiate field and render html
188:         $field = $fieldset->addField($this->getMainFieldsetHtmlId() . '_' . $fieldName, $fieldType, $data);
189:         if ($fieldRenderer) {
190:             $field->setRenderer($fieldRenderer);
191:         }
192: 
193:         // extra html preparations
194:         if ($helper = $parameter->getHelperBlock()) {
195:             $helperBlock = $this->getLayout()->createBlock($helper->getType(), '', $helper->getData());
196:             if ($helperBlock instanceof Varien_Object) {
197:                 $helperBlock->setConfig($helper->getData())
198:                     ->setFieldsetId($fieldset->getId())
199:                     ->setTranslationHelper($this->_translationHelper)
200:                     ->prepareElementHtml($field);
201:             }
202:         }
203: 
204:         // dependencies from other fields
205:         $dependenceBlock = $this->getChild('form_after');
206:         $dependenceBlock->addFieldMap($field->getId(), $fieldName);
207:         if ($parameter->getDepends()) {
208:             foreach ($parameter->getDepends() as $from => $row) {
209:                 $values = isset($row['values']) ? array_values($row['values']) : (string)$row['value'];
210:                 $dependenceBlock->addFieldDependence($fieldName, $from, $values);
211:             }
212:         }
213: 
214:         return $field;
215:     }
216: }
217: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0