/** * Retrieve list of options * * @return array */ public function toOptionArray() { if (is_null($this->_options)) { $this->_options = array(); /** @var $section Mage_Backend_Model_Config_Structure_Element_Section */ $section = $this->_configStructure->getElement('trans_email'); /** @var $group Mage_Backend_Model_Config_Structure_Element_Group */ foreach ($section->getChildren() as $group) { $this->_options[] = array('value' => preg_replace('#^ident_(.*)$#', '$1', $group->getId()), 'label' => $group->getLabel()); } ksort($this->_options); } return $this->_options; }
/** * Convert xml config pathes to decorated names * * @param array $paths * @return array */ protected function _getSystemConfigPathsParts($paths) { $result = $urlParams = $prefixParts = array(); $scopeLabel = $this->helper('Mage_Backend_Helper_Data')->__('GLOBAL'); if ($paths) { /** @var $menu Mage_Backend_Model_Menu */ $menu = $this->_menuConfig->getMenu(); $item = $menu->get('Mage_Adminhtml::system'); // create prefix path parts $prefixParts[] = array('title' => $item->getModuleHelper()->__($item->getTitle())); $item = $menu->get('Mage_Adminhtml::system_config'); $prefixParts[] = array('title' => $item->getModuleHelper()->__($item->getTitle()), 'url' => $this->getUrl('adminhtml/system_config/')); $pathParts = $prefixParts; foreach ($paths as $pathData) { $pathDataParts = explode('/', $pathData['path']); $sectionName = array_shift($pathDataParts); $urlParams = array('section' => $sectionName); if (isset($pathData['scope']) && isset($pathData['scope_id'])) { switch ($pathData['scope']) { case 'stores': $store = Mage::app()->getStore($pathData['scope_id']); if ($store) { $urlParams['website'] = $store->getWebsite()->getCode(); $urlParams['store'] = $store->getCode(); $scopeLabel = $store->getWebsite()->getName() . '/' . $store->getName(); } break; case 'websites': $website = Mage::app()->getWebsite($pathData['scope_id']); if ($website) { $urlParams['website'] = $website->getCode(); $scopeLabel = $website->getName(); } break; default: break; } } $pathParts[] = array('title' => $this->_configStructure->getElement($sectionName)->getLabel(), 'url' => $this->getUrl('adminhtml/system_config/edit', $urlParams)); $elementPathParts = array($sectionName); while (count($pathDataParts) != 1) { $elementPathParts[] = array_shift($pathDataParts); $pathParts[] = array('title' => $this->_configStructure->getElementByPathParts($elementPathParts)->getLabel()); } $elementPathParts[] = array_shift($pathDataParts); $pathParts[] = array('title' => $this->_configStructure->getElementByPathParts($elementPathParts)->getLabel(), 'scope' => $scopeLabel); $result[] = $pathParts; $pathParts = $prefixParts; } } return $result; }
/** * Prepare layout object * * @return Mage_Core_Block_Abstract */ protected function _prepareLayout() { /** @var $section Mage_Backend_Model_Config_Structure_Element_Section */ $section = $this->_configStructure->getElement($this->getRequest()->getParam('section')); $this->_formBlockName = $section->getFrontendModel(); if (empty($this->_formBlockName)) { $this->_formBlockName = self::DEFAULT_SECTION_BLOCK; } $this->setTitle($section->getLabel()); $this->setHeaderCss($section->getHeaderCss()); $this->addChild('save_button', 'Mage_Backend_Block_Widget_Button', array('label' => Mage::helper('Mage_Backend_Helper_Data')->__('Save Config'), 'class' => 'save', 'data_attribute' => array('mage-init' => array('button' => array('event' => 'save', 'target' => '#config-edit-form'))))); $block = $this->getLayout()->createBlock($this->_formBlockName); $this->setChild('form', $block); return parent::_prepareLayout(); }
/** * Check if specified section allowed in ACL * * Will forward to deniedAction(), if not allowed. * * @param string $sectionId * @throws Exception * @return bool */ protected function _isSectionAllowed($sectionId) { try { if (false == $this->_configStructure->getElement($sectionId)->isAllowed()) { throw new Exception(''); } return true; } catch (Zend_Acl_Exception $e) { $this->norouteAction(); $this->setFlag('', self::FLAG_NO_DISPATCH, true); return false; } catch (Exception $e) { $this->deniedAction(); $this->setFlag('', self::FLAG_NO_DISPATCH, true); return false; } }
/** * @param $attributeName * @param $attributeValue * @param $paths * @dataProvider getFieldPathsByAttributeDataProvider */ public function testGetFieldPathsByAttribute($attributeName, $attributeValue, $paths) { $this->assertEquals($paths, $this->_model->getFieldPathsByAttribute($attributeName, $attributeValue)); }
/** * Process group data * * @param string $groupId * @param array $groupData * @param array $groups * @param string $sectionPath * @param array $extraOldGroups * @param array $oldConfig * @param Mage_Core_Model_Resource_Transaction $saveTransaction * @param Mage_Core_Model_Resource_Transaction $deleteTransaction */ protected function _processGroup($groupId, array $groupData, array $groups, $sectionPath, array &$extraOldGroups, array &$oldConfig, Mage_Core_Model_Resource_Transaction $saveTransaction, Mage_Core_Model_Resource_Transaction $deleteTransaction) { $groupPath = $sectionPath . '/' . $groupId; $website = $this->getWebsite(); $store = $this->getStore(); $scope = $this->getScope(); $scopeId = $this->getScopeId(); /** * * Map field names if they were cloned */ /** @var $group Mage_Backend_Model_Config_Structure_Element_Group */ $group = $this->_configStructure->getElement($groupPath); // set value for group field entry by fieldname // use extra memory $fieldsetData = array(); if (isset($groupData['fields'])) { if ($group->shouldCloneFields()) { $cloneModel = $group->getCloneModel(); $mappedFields = array(); /** @var $field Mage_Backend_Model_Config_Structure_Element_Field */ foreach ($group->getChildren() as $field) { foreach ($cloneModel->getPrefixes() as $prefix) { $mappedFields[$prefix['field'] . $field->getId()] = $field->getId(); } } } foreach ($groupData['fields'] as $fieldId => $fieldData) { $fieldsetData[$fieldId] = is_array($fieldData) && isset($fieldData['value']) ? $fieldData['value'] : null; } foreach ($groupData['fields'] as $fieldId => $fieldData) { $originalFieldId = $fieldId; if ($group->shouldCloneFields() && isset($mappedFields[$fieldId])) { $originalFieldId = $mappedFields[$fieldId]; } /** @var $field Mage_Backend_Model_Config_Structure_Element_Field */ $field = $this->_configStructure->getElement($groupPath . '/' . $originalFieldId); /** @var Mage_Core_Model_Config_Data $backendModel */ $backendModel = $field->hasBackendModel() ? $field->getBackendModel() : $this->_configDataFactory->create(); $data = array('field' => $fieldId, 'groups' => $groups, 'group_id' => $group->getId(), 'store_code' => $store, 'website_code' => $website, 'scope' => $scope, 'scope_id' => $scopeId, 'field_config' => $field->getData(), 'fieldset_data' => $fieldsetData); $backendModel->addData($data); $this->_checkSingleStoreMode($field, $backendModel); if (false == isset($fieldData['value'])) { $fieldData['value'] = null; } $path = $field->getGroupPath() . '/' . $fieldId; /** * Look for custom defined field path */ if ($field && $field->getConfigPath()) { $configPath = $field->getConfigPath(); if (!empty($configPath) && strrpos($configPath, '/') > 0) { // Extend old data with specified section group $configGroupPath = substr($configPath, 0, strrpos($configPath, '/')); if (!isset($extraOldGroups[$configGroupPath])) { $oldConfig = $this->extendConfig($configGroupPath, true, $oldConfig); $extraOldGroups[$configGroupPath] = true; } $path = $configPath; } } $inherit = !empty($fieldData['inherit']); $backendModel->setPath($path)->setValue($fieldData['value']); if (isset($oldConfig[$path])) { $backendModel->setConfigId($oldConfig[$path]['config_id']); /** * Delete config data if inherit */ if (!$inherit) { $saveTransaction->addObject($backendModel); } else { $deleteTransaction->addObject($backendModel); } } elseif (!$inherit) { $backendModel->unsConfigId(); $saveTransaction->addObject($backendModel); } } } if (isset($groupData['groups'])) { foreach ($groupData['groups'] as $subGroupId => $subGroupData) { $this->_processGroup($subGroupId, $subGroupData, $groups, $groupPath, $extraOldGroups, $oldConfig, $saveTransaction, $deleteTransaction); } } }
public function testGetEncryptedNodeEntriesPathsReturnsListOfEncryptedFieldPathsReturnsExplodedPaths() { $expected = array(array('section' => 'section_1', 'group' => 'group_1', 'field' => 'field_2'), array('section' => 'section_2', 'group' => 'group_3', 'field' => 'field_4')); $this->assertEquals($expected, $this->_model->getEncryptedNodeEntriesPaths(true)); }
/** * Initialize form * * @return Mage_Backend_Block_System_Config_Form */ public function initForm() { $this->_initObjects(); /** @var Varien_Data_Form $form */ $form = $this->_formFactory->create(); /** @var $section Mage_Backend_Model_Config_Structure_Element_Section */ $section = $this->_configStructure->getElement($this->getSectionCode()); if ($section && $section->isVisible($this->getWebsiteCode(), $this->getStoreCode())) { foreach ($section->getChildren() as $group) { $this->_initGroup($group, $section, $form); } } $this->setForm($form); return $this; }
/** * @param Mage_Core_Controller_Request_Http $request * @param Mage_Core_Model_Layout $layout * @param Mage_Core_Model_Event_Manager $eventManager * @param Mage_Backend_Model_Url $urlBuilder * @param Mage_Core_Model_Translate $translator * @param Mage_Core_Model_Cache $cache * @param Mage_Core_Model_Design_Package $designPackage * @param Mage_Core_Model_Session $session * @param Mage_Core_Model_Store_Config $storeConfig * @param Mage_Core_Controller_Varien_Front $frontController * @param Mage_Core_Model_Factory_Helper $helperFactory * @param Magento_Filesystem $filesystem * @param Mage_Backend_Model_Config_Structure $configStructure * @param array $data * * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct(Mage_Core_Controller_Request_Http $request, Mage_Core_Model_Layout $layout, Mage_Core_Model_Event_Manager $eventManager, Mage_Backend_Model_Url $urlBuilder, Mage_Core_Model_Translate $translator, Mage_Core_Model_Cache $cache, Mage_Core_Model_Design_Package $designPackage, Mage_Core_Model_Session $session, Mage_Core_Model_Store_Config $storeConfig, Mage_Core_Controller_Varien_Front $frontController, Mage_Core_Model_Factory_Helper $helperFactory, Magento_Filesystem $filesystem, Mage_Backend_Model_Config_Structure $configStructure, array $data = array()) { parent::__construct($request, $layout, $eventManager, $urlBuilder, $translator, $cache, $designPackage, $session, $storeConfig, $frontController, $helperFactory, $filesystem, $data); $this->_tabs = $configStructure->getTabs(); $this->setId('system_config_tabs'); $this->setTitle($this->helper('Mage_Backend_Helper_Data')->__('Configuration')); $this->_currentSectionId = $this->getRequest()->getParam('section'); $this->helper('Mage_Backend_Helper_Data')->addPageHelpUrl($this->getRequest()->getParam('section') . '/'); }