Beispiel #1
0
 /**
  * @param \Magento\Backend\Block\Template\Context $context
  * @param \Magento\Backend\Model\Config\Structure $configStructure
  * @param \Magento\Backend\Helper\Data $backendHelper
  * @param array $data
  */
 public function __construct(\Magento\Backend\Block\Template\Context $context, \Magento\Backend\Model\Config\Structure $configStructure, \Magento\Backend\Helper\Data $backendHelper, array $data = [])
 {
     $this->_backendHelper = $backendHelper;
     parent::__construct($context, $data);
     $this->_tabs = $configStructure->getTabs();
     $this->setId('system_config_tabs');
     $this->setTitle(__('Configuration'));
     $this->_currentSectionId = $this->getRequest()->getParam('section');
     $this->_backendHelper->addPageHelpUrl($this->getRequest()->getParam('section') . '/');
 }
 /**
  * Check if specified section allowed in ACL
  *
  * Will forward to deniedAction(), if not allowed.
  *
  * @param string $sectionId
  * @throws \Exception
  * @return bool
  * @throws NotFoundException
  */
 public function isSectionAllowed($sectionId)
 {
     try {
         if (false == $this->_configStructure->getElement($sectionId)->isAllowed()) {
             throw new \Exception('');
         }
         return true;
     } catch (\Zend_Acl_Exception $e) {
         throw new NotFoundException();
     } catch (\Exception $e) {
         return false;
     }
 }
Beispiel #3
0
 /**
  * Retrieve list of options
  *
  * @return array
  */
 public function toOptionArray()
 {
     if (is_null($this->_options)) {
         $this->_options = [];
         /** @var $section \Magento\Backend\Model\Config\Structure\Element\Section */
         $section = $this->_configStructure->getElement('trans_email');
         /** @var $group \Magento\Backend\Model\Config\Structure\Element\Group */
         foreach ($section->getChildren() as $group) {
             $this->_options[] = ['value' => preg_replace('#^ident_(.*)$#', '$1', $group->getId()), 'label' => $group->getLabel()];
         }
         ksort($this->_options);
     }
     return $this->_options;
 }
 /**
  * Check if specified section allowed in ACL
  *
  * Will forward to deniedAction(), if not allowed.
  *
  * @param string $sectionId
  * @throws \Exception
  * @return bool
  * @throws NotFoundException
  */
 protected function _isSectionAllowed($sectionId)
 {
     try {
         if (false == $this->_configStructure->getElement($sectionId)->isAllowed()) {
             throw new \Exception('');
         }
         return true;
     } catch (\Zend_Acl_Exception $e) {
         throw new NotFoundException();
     } catch (\Exception $e) {
         $this->deniedAction();
         $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true);
         return false;
     }
 }
Beispiel #5
0
 /**
  * Prepare layout object
  *
  * @return \Magento\Framework\View\Element\AbstractBlock
  */
 protected function _prepareLayout()
 {
     /** @var $section \Magento\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->getToolbar()->addChild('save_button', 'Magento\\Backend\\Block\\Widget\\Button', array('id' => 'save', 'label' => __('Save Config'), 'class' => 'save primary', '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();
 }
Beispiel #6
0
 /**
  * Convert xml config paths to decorated names
  *
  * @param array $paths
  * @return array
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 protected function _getSystemConfigPathsParts($paths)
 {
     $result = $urlParams = $prefixParts = array();
     $scopeLabel = __('GLOBAL');
     if ($paths) {
         /** @var $menu \Magento\Backend\Model\Menu */
         $menu = $this->_menuConfig->getMenu();
         $item = $menu->get('Magento_Backend::stores');
         // create prefix path parts
         $prefixParts[] = array('title' => __($item->getTitle()));
         $item = $menu->get('Magento_Backend::system_config');
         $prefixParts[] = array('title' => __($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 = $this->_storeManager->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 = $this->_storeManager->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;
 }
Beispiel #7
0
 /**
  * Initialize form
  *
  * @return $this
  */
 public function initForm()
 {
     $this->_initObjects();
     /** @var \Magento\Framework\Data\Form $form */
     $form = $this->_formFactory->create();
     /** @var $section \Magento\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;
 }
Beispiel #8
0
 /**
  * Collect all system config paths where current template is currently used
  *
  * @return array
  */
 public function getSystemConfigPathsWhereUsedCurrently()
 {
     $templateId = $this->getId();
     if (!$templateId) {
         return array();
     }
     $templatePaths = $this->_structure->getFieldPathsByAttribute('source_model', 'Magento\\Backend\\Model\\Config\\Source\\Email\\Template');
     if (!count($templatePaths)) {
         return array();
     }
     $configData = $this->_getResource()->getSystemConfigByPathsAndTemplateId($templatePaths, $templateId);
     if (!$configData) {
         return array();
     }
     return $configData;
 }
Beispiel #9
0
 public function testSaveToCheckScopeDataSet()
 {
     $transactionMock = $this->getMock('Magento\\Framework\\DB\\Transaction', array(), array(), '', false);
     $this->_transFactoryMock->expects($this->any())->method('create')->will($this->returnValue($transactionMock));
     $this->_configLoaderMock->expects($this->any())->method('getConfigByPath')->will($this->returnValue(array()));
     $this->_eventManagerMock->expects($this->at(0))->method('dispatch')->with($this->equalTo('admin_system_config_changed_section_'), $this->arrayHasKey('website'));
     $this->_eventManagerMock->expects($this->at(0))->method('dispatch')->with($this->equalTo('admin_system_config_changed_section_'), $this->arrayHasKey('store'));
     $group = $this->getMock('Magento\\Backend\\Model\\Config\\Structure\\Element\\Group', array(), array(), '', false);
     $field = $this->getMock('Magento\\Backend\\Model\\Config\\Structure\\Element\\Field', array(), array(), '', false);
     $this->_configStructure->expects($this->at(0))->method('getElement')->with('/1')->will($this->returnValue($group));
     $this->_configStructure->expects($this->at(1))->method('getElement')->with('/1/key')->will($this->returnValue($field));
     $website = $this->getMock('Magento\\Store\\Model\\Website', array(), array(), '', false);
     $this->_storeManager->expects($this->any())->method('getWebsite')->will($this->returnValue($website));
     $this->_storeManager->expects($this->any())->method('getWebsites')->will($this->returnValue(array($website)));
     $this->_storeManager->expects($this->any())->method('isSingleStoreMode')->will($this->returnValue(true));
     $this->_model->setWebsite('website');
     $this->_model->setGroups(array('1' => array('fields' => array('key' => array('data')))));
     $backendModel = $this->getMock('Magento\\Framework\\App\\Config\\Value', array('setPath', 'addData', '__sleep', '__wakeup'), array(), '', false);
     $backendModel->expects($this->once())->method('addData')->with(array('field' => 'key', 'groups' => array(1 => array('fields' => array('key' => array('data')))), 'group_id' => null, 'scope' => 'websites', 'scope_id' => 0, 'scope_code' => 'website', 'field_config' => null, 'fieldset_data' => array('key' => null)));
     $backendModel->expects($this->once())->method('setPath')->with('/key')->will($this->returnValue($backendModel));
     $this->_dataFactoryMock->expects($this->any())->method('create')->will($this->returnValue($backendModel));
     $this->_model->save();
 }
Beispiel #10
0
 /**
  * Process group data
  *
  * @param string $groupId
  * @param array $groupData
  * @param array $groups
  * @param string $sectionPath
  * @param array &$extraOldGroups
  * @param array &$oldConfig
  * @param \Magento\Framework\DB\Transaction $saveTransaction
  * @param \Magento\Framework\DB\Transaction $deleteTransaction
  * @return void
  */
 protected function _processGroup($groupId, array $groupData, array $groups, $sectionPath, array &$extraOldGroups, array &$oldConfig, \Magento\Framework\DB\Transaction $saveTransaction, \Magento\Framework\DB\Transaction $deleteTransaction)
 {
     $groupPath = $sectionPath . '/' . $groupId;
     $scope = $this->getScope();
     $scopeId = $this->getScopeId();
     $scopeCode = $this->getScopeCode();
     /**
      *
      * Map field names if they were cloned
      */
     /** @var $group \Magento\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 \Magento\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 \Magento\Backend\Model\Config\Structure\Element\Field */
             $field = $this->_configStructure->getElement($groupPath . '/' . $originalFieldId);
             /** @var \Magento\Framework\App\Config\ValueInterface $backendModel */
             $backendModel = $field->hasBackendModel() ? $field->getBackendModel() : $this->_configValueFactory->create();
             $data = array('field' => $fieldId, 'groups' => $groups, 'group_id' => $group->getId(), 'scope' => $scope, 'scope_id' => $scopeId, 'scope_code' => $scopeCode, '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);
         }
     }
 }
Beispiel #11
0
 /**
  * Check is allow modify system configuration
  *
  * @return bool
  */
 protected function _isAllowed()
 {
     $sectionId = $this->_request->getParam('section');
     return $this->_authorization->isAllowed('Magento_Adminhtml::config') || $this->_configStructure->getElement($sectionId)->isAllowed();
 }
Beispiel #12
0
 /**
  * @param $attributeName
  * @param $attributeValue
  * @param $paths
  * @dataProvider getFieldPathsByAttributeDataProvider
  */
 public function testGetFieldPathsByAttribute($attributeName, $attributeValue, $paths)
 {
     $this->assertEquals($paths, $this->_model->getFieldPathsByAttribute($attributeName, $attributeValue));
 }