Mage_Adminhtml_Block_System_Config_Form Class Reference

Inheritance diagram for Mage_Adminhtml_Block_System_Config_Form:

Mage_Adminhtml_Block_Widget_Form Mage_Adminhtml_Block_Widget Mage_Adminhtml_Block_Template Mage_Core_Block_Template Mage_Core_Block_Abstract Varien_Object

List of all members.

Public Member Functions

 __construct ()
 initForm ()
 initFields ($fieldset, $group, $section, $fieldPrefix='', $labelPrefix='')
 canUseDefaultValue ($field)
 canUseWebsiteValue ($field)
 getScope ()
 getScopeCode ()
 getScopeId ()
 getSectionCode ()
 getWebsiteCode ()
 getStoreCode ()

Public Attributes

const SCOPE_DEFAULT = 'default'
const SCOPE_WEBSITES = 'websites'
const SCOPE_STORES = 'stores'

Protected Member Functions

 _initObjects ()
 _sortForm ($a, $b)
 _canShowField ($field)
 _getAdditionalElementTypes ()

Protected Attributes

 $_configData
 $_configRoot
 $_configFields
 $_defaultFieldsetRenderer
 $_defaultFieldRenderer
 $_fieldsets = array()


Detailed Description

Definition at line 35 of file Form.php.


Constructor & Destructor Documentation

__construct (  ) 

Enter description here...

Reimplemented from Mage_Adminhtml_Block_Widget_Form.

Definition at line 88 of file Form.php.

00089     {
00090         parent::__construct();
00091     }


Member Function Documentation

_canShowField ( field  )  [protected]

Checking field visibility

Parameters:
Varien_Simplexml_Element $field
Returns:
bool

Definition at line 335 of file Form.php.

00336     {
00337         switch ($this->getScope()) {
00338             case self::SCOPE_DEFAULT:
00339                 return (int)$field->show_in_default;
00340                 break;
00341             case self::SCOPE_WEBSITES:
00342                 return (int)$field->show_in_website;
00343                 break;
00344             case self::SCOPE_STORES:
00345                 return (int)$field->show_in_store;
00346                 break;
00347         }
00348         return true;
00349     }

_getAdditionalElementTypes (  )  [protected]

Enter description here...

Returns:
array

Reimplemented from Mage_Adminhtml_Block_Widget_Form.

Definition at line 421 of file Form.php.

00422     {
00423         return array(
00424             'export'        => Mage::getConfig()->getBlockClassName('adminhtml/system_config_form_field_export'),
00425             'import'        => Mage::getConfig()->getBlockClassName('adminhtml/system_config_form_field_import'),
00426             'allowspecific' => Mage::getConfig()->getBlockClassName('adminhtml/system_config_form_field_select_allowspecific'),
00427             'image'         => Mage::getConfig()->getBlockClassName('adminhtml/system_config_form_field_image'),
00428         );
00429     }

_initObjects (  )  [protected]

Enter description here...

Returns:
Mage_Adminhtml_Block_System_Config_Form

Definition at line 98 of file Form.php.

00099     {
00100         $this->_configRoot = Mage::getConfig()->getNode(null, $this->getScope(), $this->getScopeCode());
00101 
00102         $this->_configData = Mage::getModel('adminhtml/config_data')
00103             ->setSection($this->getSectionCode())
00104             ->setWebsite($this->getWebsiteCode())
00105             ->setStore($this->getStoreCode())
00106             ->load();
00107 
00108         $this->_configFields = Mage::getSingleton('adminhtml/config');
00109 
00110         $this->_defaultFieldsetRenderer = Mage::getBlockSingleton('adminhtml/system_config_form_fieldset');
00111         $this->_defaultFieldRenderer = Mage::getBlockSingleton('adminhtml/system_config_form_field');
00112         return $this;
00113     }

_sortForm ( a,
b 
) [protected]

Enter description here...

Parameters:
Varien_Simplexml_Element $a
Varien_Simplexml_Element $b
Returns:
boolean

Definition at line 292 of file Form.php.

00293     {
00294         return (int)$a->sort_order < (int)$b->sort_order ? -1 : ((int)$a->sort_order > (int)$b->sort_order ? 1 : 0);
00295 
00296     }

canUseDefaultValue ( field  ) 

Enter description here...

Parameters:
Varien_Simplexml_Element $field
Returns:
boolean

Definition at line 304 of file Form.php.

00305     {
00306         if ($this->getScope() == self::SCOPE_STORES && $field) {
00307             return true;
00308         }
00309         if ($this->getScope() == self::SCOPE_WEBSITES && $field) {
00310             return true;
00311         }
00312         return false;
00313     }

canUseWebsiteValue ( field  ) 

Enter description here...

Parameters:
Varien_Simplexml_Element $field
Returns:
boolean

Definition at line 321 of file Form.php.

00322     {
00323         if ($this->getScope() == self::SCOPE_STORES && $field) {
00324             return true;
00325         }
00326         return false;
00327     }

getScope (  ) 

Retrieve current scope

Returns:
string

Definition at line 356 of file Form.php.

00357     {
00358         $scope = $this->getData('scope');
00359         if (is_null($scope)) {
00360             if ($this->getStoreCode()) {
00361                 $scope = self::SCOPE_STORES;
00362             } elseif ($this->getWebsiteCode()) {
00363                 $scope = self::SCOPE_WEBSITES;
00364             } else {
00365                 $scope = self::SCOPE_DEFAULT;
00366             }
00367             $this->setScope($scope);
00368         }
00369 
00370         return $scope;
00371     }

getScopeCode (  ) 

Get current scope code

Returns:
string

Definition at line 378 of file Form.php.

00379     {
00380         $scopeCode = $this->getData('scope_code');
00381         if (is_null($scopeCode)) {
00382             if ($this->getStoreCode()) {
00383                 $scopeCode = $this->getStoreCode();
00384             } elseif ($this->getWebsiteCode()) {
00385                 $scopeCode = $this->getWebsiteCode();
00386             } else {
00387                 $scopeCode = '';
00388             }
00389             $this->setScopeCode($scopeCode);
00390         }
00391 
00392         return $scopeCode;
00393     }

getScopeId (  ) 

Get current scope code

Returns:
int|string

Definition at line 400 of file Form.php.

00401     {
00402         $scopeId = $this->getData('scope_id');
00403         if (is_null($scopeId)) {
00404             if ($this->getStoreCode()) {
00405                 $scopeId = Mage::app()->getStore($this->getStoreCode())->getId();
00406             } elseif ($this->getWebsiteCode()) {
00407                 $scopeId = Mage::app()->getWebsite($this->getWebsiteCode())->getId();
00408             } else {
00409                 $scopeId = '';
00410             }
00411             $this->setScopeId($scopeId);
00412         }
00413         return $scopeId;
00414     }

getSectionCode (  ) 

Temporary moved those $this->getRequest()->getParam('blabla') from the code accross this block to getBlala() methods to be later set from controller with setters Enter description here...

delete this methods when {^see above^} is done

Returns:
string

Definition at line 441 of file Form.php.

00442     {
00443         return $this->getRequest()->getParam('section', '');
00444     }

getStoreCode (  ) 

Enter description here...

delete this methods when {^see above^} is done

Returns:
string

Definition at line 463 of file Form.php.

00464     {
00465         return $this->getRequest()->getParam('store', '');
00466     }

getWebsiteCode (  ) 

Enter description here...

delete this methods when {^see above^} is done

Returns:
string

Definition at line 452 of file Form.php.

00453     {
00454         return $this->getRequest()->getParam('website', '');
00455     }

initFields ( fieldset,
group,
section,
fieldPrefix = '',
labelPrefix = '' 
)

Init fieldset fields

Parameters:
Varien_Data_Form_Element_Fieldset $fieldset
Varien_Simplexml_Element $group
Varien_Simplexml_Element $section
string $fieldPrefix
string $labelPrefix
Returns:
Mage_Adminhtml_Block_System_Config_Form

Definition at line 204 of file Form.php.

00205     {
00206         foreach ($group->fields as $elements) {
00207 
00208             $elements = (array)$elements;
00209             usort($elements, array($this, '_sortForm'));
00210 
00211             foreach ($elements as $e) {
00212                 if (!$this->_canShowField($e)) {
00213                     continue;
00214                 }
00215                 $path = $section->getName() . '/' . $group->getName() . '/' . $fieldPrefix . $e->getName();
00216                 $id = $section->getName() . '_' . $group->getName() . '_' . $fieldPrefix . $e->getName();
00217 
00218                 if (isset($this->_configData[$path])) {
00219                     $data = $this->_configData[$path];
00220                     $inherit = false;
00221                 } else {
00222                     $data = $this->_configRoot->descend($path);
00223                     $inherit = true;
00224                 }
00225                 if ($e->frontend_model) {
00226                     $fieldRenderer = Mage::getBlockSingleton((string)$e->frontend_model);
00227                 } else {
00228                     $fieldRenderer = $this->_defaultFieldRenderer;
00229                 }
00230 
00231                 $fieldRenderer->setForm($this);
00232                 $fieldRenderer->setConfigData($this->_configData);
00233 
00234                 $helperName = $this->_configFields->getAttributeModule($section, $group, $e);
00235                 $fieldType  = (string)$e->frontend_type ? (string)$e->frontend_type : 'text';
00236                 $name       = 'groups['.$group->getName().'][fields]['.$fieldPrefix.$e->getName().'][value]';
00237                 $label      =  Mage::helper($helperName)->__($labelPrefix).' '.Mage::helper($helperName)->__((string)$e->label);
00238                 $comment    = (string)$e->comment ? Mage::helper($helperName)->__((string)$e->comment) : '';
00239 
00240                 if ($e->backend_model) {
00241                     $model = Mage::getModel((string)$e->backend_model);
00242                     if (!$model instanceof Mage_Core_Model_Config_Data) {
00243                         Mage::throwException('Invalid config field backend model: '.(string)$e->backend_model);
00244                     }
00245                     $model->setPath($path)->setValue($data)->afterLoad();
00246                     $data = $model->getValue();
00247                 }
00248                 $field = $fieldset->addField($id, $fieldType, array(
00249                     'name'                  => $name,
00250                     'label'                 => $label,
00251                     'comment'               => $comment,
00252                     'value'                 => $data,
00253                     'inherit'               => $inherit,
00254                     'class'                 => $e->frontend_class,
00255                     'field_config'          => $e,
00256                     'scope'                 => $this->getScope(),
00257                     'scope_id'              => $this->getScopeId(),
00258                     'can_use_default_value' => $this->canUseDefaultValue((int)$e->show_in_default),
00259                     'can_use_website_value' => $this->canUseWebsiteValue((int)$e->show_in_website),
00260                 ));
00261 
00262                 if (isset($e->validate)) {
00263                     $field->addClass($e->validate);
00264                 }
00265 
00266                 if (isset($e->frontend_type) && 'multiselect' === (string)$e->frontend_type && isset($e->can_be_empty)) {
00267                     $field->setCanBeEmpty(true);
00268                 }
00269 
00270                 $field->setRenderer($fieldRenderer);
00271 
00272                 if ($e->source_model) {
00273                     $sourceModel = Mage::getSingleton((string)$e->source_model);
00274                     if ($sourceModel instanceof Varien_Object) {
00275                         $sourceModel->setPath($path);
00276                     }
00277                     $field->setValues($sourceModel->toOptionArray($fieldType == 'multiselect'));
00278                 }
00279             }
00280         }
00281         return $this;
00282     }

initForm (  ) 

Enter description here...

Returns:
Mage_Adminhtml_Block_System_Config_Form

Definition at line 120 of file Form.php.

00121     {
00122         $this->_initObjects();
00123 
00124         $form = new Varien_Data_Form();
00125 
00126         $sections = $this->_configFields->getSection($this->getSectionCode(), $this->getWebsiteCode(), $this->getStoreCode());
00127         if (empty($sections)) {
00128             $sections = array();
00129         }
00130         foreach ($sections as $section) {
00131             /* @var $section Varien_Simplexml_Element */
00132             if (!$this->_canShowField($section)) {
00133                 continue;
00134             }
00135             foreach ($section->groups as $groups){
00136 
00137                 $groups = (array)$groups;
00138                 usort($groups, array($this, '_sortForm'));
00139 
00140                 foreach ($groups as $group){
00141                     /* @var $group Varien_Simplexml_Element */
00142                     if (!$this->_canShowField($group)) {
00143                         continue;
00144                     }
00145 
00146                     if ($group->frontend_model) {
00147                         $fieldsetRenderer = Mage::getBlockSingleton((string)$group->frontend_model);
00148                     } else {
00149                         $fieldsetRenderer = $this->_defaultFieldsetRenderer;
00150                     }
00151 
00152                     $fieldsetRenderer->setForm($this);
00153                     $fieldsetRenderer->setConfigData($this->_configData);
00154                     $fieldsetRenderer->setGroup($group);
00155 
00156                     if ($this->_configFields->hasChildren($group, $this->getWebsiteCode(), $this->getStoreCode())) {
00157 
00158                         $helperName = $this->_configFields->getAttributeModule($section, $group);
00159 
00160                         $fieldsetConfig = array('legend' => Mage::helper($helperName)->__((string)$group->label));
00161                         if (!empty($group->comment)) {
00162                             $fieldsetConfig['comment'] = (string)$group->comment;
00163                         }
00164 
00165                         $fieldset = $form->addFieldset(
00166                             $section->getName() . '_' . $group->getName(), $fieldsetConfig)
00167                             ->setRenderer($fieldsetRenderer);
00168                         $this->_addElementTypes($fieldset);
00169 
00170                         if ($group->clone_fields) {
00171                             if ($group->clone_model) {
00172                                 $cloneModel = Mage::getModel((string)$group->clone_model);
00173                             } else {
00174                                 Mage::throwException('Config form fieldset clone model required to be able to clone fields');
00175                             }
00176                             foreach ($cloneModel->getPrefixes() as $prefix) {
00177                                 $this->initFields($fieldset, $group, $section, $prefix['field'], $prefix['label']);
00178                             }
00179                         } else {
00180                             $this->initFields($fieldset, $group, $section);
00181                         }
00182 
00183                         $this->_fieldsets[$group->getName()] = $fieldset;
00184 
00185                     }
00186                 }
00187             }
00188         }
00189 
00190         $this->setForm($form);
00191         return $this;
00192     }


Member Data Documentation

$_configData [protected]

Definition at line 47 of file Form.php.

$_configFields [protected]

Definition at line 61 of file Form.php.

$_configRoot [protected]

Definition at line 54 of file Form.php.

$_defaultFieldRenderer [protected]

Definition at line 75 of file Form.php.

$_defaultFieldsetRenderer [protected]

Definition at line 68 of file Form.php.

$_fieldsets = array() [protected]

Definition at line 82 of file Form.php.

const SCOPE_DEFAULT = 'default'

Definition at line 38 of file Form.php.

const SCOPE_STORES = 'stores'

Definition at line 40 of file Form.php.

const SCOPE_WEBSITES = 'websites'

Definition at line 39 of file Form.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:23:03 2009 for Magento by  doxygen 1.5.8