示例#1
0
文件: Form.php 项目: rorteg/magento2
 /**
  * Apply element dependencies from configuration
  *
  * @param Varien_SimpleXml_Element $element
  * @param Varien_SimpleXml_Element $section
  * @param Varien_SimpleXml_Element $group
  * @param string $elementId
  * @param string $fieldPrefix
  */
 protected function _processElementDependencies($element, $section, $group, $elementId, $fieldPrefix = '')
 {
     foreach ($element->depends->children() as $dependent) {
         /* @var $dependent Mage_Core_Model_Config_Element */
         $dependentId = $section->getName() . '_' . $group->getName() . '_' . $fieldPrefix . $dependent->getName();
         $shouldBeAddedDependence = true;
         $dependentValue = (string) $dependent;
         if (isset($dependent['separator'])) {
             $dependentValue = explode((string) $dependent['separator'], $dependentValue);
         }
         $dependentFieldName = $fieldPrefix . $dependent->getName();
         $dependentField = $group->fields->{$dependentFieldName};
         /*
          * If dependent field can't be shown in current scope and real dependent config value
          * is not equal to preferred one, then hide dependence fields by adding dependence
          * based on not shown field (not rendered field)
          */
         if (!$this->_canShowField($dependentField)) {
             $dependentFullPath = $section->getName() . '/' . $group->getName() . '/' . $fieldPrefix . $dependent->getName();
             $dependentValueInStore = Mage::getStoreConfig($dependentFullPath, $this->getStoreCode());
             if (is_array($dependentValue)) {
                 $shouldBeAddedDependence = !in_array($dependentValueInStore, $dependentValue);
             } else {
                 $shouldBeAddedDependence = $dependentValue != $dependentValueInStore;
             }
         }
         if ($shouldBeAddedDependence) {
             $this->_getDependence()->addFieldMap($elementId, $elementId)->addFieldMap($dependentId, $dependentId)->addFieldDependence($elementId, $dependentId, $dependentValue);
         }
     }
 }
示例#2
0
 /**
  * Collects action arguments
  *
  * @param Varien_SimpleXml_Element $node
  * @return array|null
  */
 protected function _collectActionArguments($node)
 {
     if (isset($node['ifconfig']) && !Mage::getStoreConfigFlag((string) $node['ifconfig'])) {
         return null;
     }
     $args = (array) $node->children();
     unset($args['@attributes']);
     foreach ($args as $key => $arg) {
         if ($arg instanceof Mage_Core_Model_Layout_Element) {
             if (isset($arg['helper'])) {
                 $helperName = explode('/', (string) $arg['helper']);
                 $helperMethod = array_pop($helperName);
                 $helperName = implode('/', $helperName);
                 $arg = $arg->asArray();
                 unset($arg['@']);
                 $args[$key] = call_user_func_array(array(Mage::helper($helperName), $helperMethod), $arg);
             } else {
                 /**
                  * if there is no helper we hope that this is assoc array
                  */
                 $arr = array();
                 foreach ($arg as $subkey => $value) {
                     $arr[(string) $subkey] = $value->asArray();
                 }
                 if (!empty($arr)) {
                     $args[$key] = $arr;
                 }
             }
         }
     }
     if (isset($node['json'])) {
         $json = explode(' ', (string) $node['json']);
         foreach ($json as $arg) {
             $args[$arg] = Mage::helper('core')->jsonDecode($args[$arg]);
         }
     }
     return $args;
 }