本文整理汇总了PHP中Varien_Data_Form_Element_Fieldset::setSortElementsByAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP Varien_Data_Form_Element_Fieldset::setSortElementsByAttribute方法的具体用法?PHP Varien_Data_Form_Element_Fieldset::setSortElementsByAttribute怎么用?PHP Varien_Data_Form_Element_Fieldset::setSortElementsByAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Varien_Data_Form_Element_Fieldset
的用法示例。
在下文中一共展示了Varien_Data_Form_Element_Fieldset::setSortElementsByAttribute方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initFields
/**
* Init fieldset fields
*
* @param Varien_Data_Form_Element_Fieldset $fieldset
* @param Varien_Simplexml_Element $group
* @param Varien_Simplexml_Element $section
* @param string $fieldPrefix
* @param string $labelPrefix
* @return Mage_Adminhtml_Block_System_Config_Form
*/
public function initFields($fieldset, $group, $section, $fieldPrefix = '', $labelPrefix = '')
{
if (!$this->_configDataObject) {
$this->_initObjects();
}
// Extends for config data
$configDataAdditionalGroups = array();
foreach ($group->fields as $elements) {
$elements = (array) $elements;
// sort either by sort_order or by child node values bypassing the sort_order
if ($group->sort_fields && $group->sort_fields->by) {
$fieldset->setSortElementsByAttribute((string) $group->sort_fields->by, $group->sort_fields->direction_desc ? SORT_DESC : SORT_ASC);
} else {
usort($elements, array($this, '_sortForm'));
}
foreach ($elements as $element) {
if (!$this->_canShowField($element)) {
continue;
}
if ((string) $element->getAttribute('type') == 'group') {
$this->_initGroup($fieldset->getForm(), $element, $section, $fieldset);
continue;
}
/**
* Look for custom defined field path
*/
$path = (string) $element->config_path;
if (empty($path)) {
$path = $section->getName() . '/' . $group->getName() . '/' . $fieldPrefix . $element->getName();
} elseif (strrpos($path, '/') > 0) {
// Extend config data with new section group
$groupPath = substr($path, 0, strrpos($path, '/'));
if (!isset($configDataAdditionalGroups[$groupPath])) {
$this->_configData = $this->_configDataObject->extendConfig($groupPath, false, $this->_configData);
$configDataAdditionalGroups[$groupPath] = true;
}
}
$data = $this->_configDataObject->getConfigDataValue($path, $inherit, $this->_configData);
if ($element->frontend_model) {
$fieldRenderer = Mage::getBlockSingleton((string) $element->frontend_model);
} else {
$fieldRenderer = $this->_defaultFieldRenderer;
}
$fieldRenderer->setForm($this);
$fieldRenderer->setConfigData($this->_configData);
$helperName = $this->_configFields->getAttributeModule($section, $group, $element);
$fieldType = (string) $element->frontend_type ? (string) $element->frontend_type : 'text';
$name = 'groups[' . $group->getName() . '][fields][' . $fieldPrefix . $element->getName() . '][value]';
$label = Mage::helper($helperName)->__($labelPrefix) . ' ' . Mage::helper($helperName)->__((string) $element->label);
$hint = (string) $element->hint ? Mage::helper($helperName)->__((string) $element->hint) : '';
if ($element->backend_model) {
$model = Mage::getModel((string) $element->backend_model);
if (!$model instanceof Mage_Core_Model_Config_Data) {
Mage::throwException('Invalid config field backend model: ' . (string) $element->backend_model);
}
$model->setPath($path)->setValue($data)->setWebsite($this->getWebsiteCode())->setStore($this->getStoreCode())->afterLoad();
$data = $model->getValue();
}
$comment = $this->_prepareFieldComment($element, $helperName, $data);
$tooltip = $this->_prepareFieldTooltip($element, $helperName);
$id = $section->getName() . '_' . $group->getName() . '_' . $fieldPrefix . $element->getName();
if ($element->depends) {
foreach ($element->depends->children() as $dependent) {
/* @var $dependent Mage_Core_Model_Config_Element */
if (isset($dependent->fieldset)) {
$dependentFieldGroupName = (string) $dependent->fieldset;
if (!isset($this->_fieldsets[$dependentFieldGroupName])) {
$dependentFieldGroupName = $group->getName();
}
} else {
$dependentFieldGroupName = $group->getName();
}
$dependentFieldNameValue = $dependent->getName();
$dependentFieldGroup = $dependentFieldGroupName == $group->getName() ? $group : $this->_fieldsets[$dependentFieldGroupName]->getGroup();
$dependentId = $section->getName() . '_' . $dependentFieldGroupName . '_' . $fieldPrefix . $dependentFieldNameValue;
$shouldBeAddedDependence = true;
$dependentValue = (string) (isset($dependent->value) ? $dependent->value : $dependent);
if (isset($dependent['separator'])) {
$dependentValue = explode((string) $dependent['separator'], $dependentValue);
}
$dependentFieldName = $fieldPrefix . $dependent->getName();
$dependentField = $dependentFieldGroup->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() . '/' . $dependentFieldGroupName . '/' . $fieldPrefix . $dependent->getName();
$dependentValueInStore = Mage::getStoreConfig($dependentFullPath, $this->getStoreCode());
//.........这里部分代码省略.........
示例2: _sortElements
/**
* @param array $group
* @param Varien_Data_Form_Element_Fieldset $fieldset
* @param array $elements
* @return mixed
*/
protected function _sortElements($group, $fieldset, $elements)
{
if (isset($group['sort_fields']) && isset($group['sort_fields']['by'])) {
$fieldset->setSortElementsByAttribute($group['sort_fields']['by'], isset($group['sort_fields']['direction_desc']) ? SORT_DESC : SORT_ASC);
} else {
usort($elements, array($this, '_sortForm'));
}
return $elements;
}
示例3: initFields
/**
* Init fieldset fields
*
* @param Varien_Data_Form_Element_Fieldset $fieldset
* @param Varien_Simplexml_Element $group
* @param Varien_Simplexml_Element $section
* @param string $fieldPrefix
* @param string $labelPrefix
* @return Mage_Adminhtml_Block_System_Config_Form
*/
public function initFields($fieldset, $group, $section, $fieldPrefix = '', $labelPrefix = '')
{
foreach ($group->fields as $elements) {
$elements = (array) $elements;
// sort either by sort_order or by child node values bypassing the sort_order
if ($group->sort_fields && $group->sort_fields->by) {
$fieldset->setSortElementsByAttribute((string) $group->sort_fields->by, $group->sort_fields->direction_desc ? SORT_DESC : SORT_ASC);
} else {
usort($elements, array($this, '_sortForm'));
}
foreach ($elements as $e) {
if (!$this->_canShowField($e)) {
continue;
}
$path = $section->getName() . '/' . $group->getName() . '/' . $fieldPrefix . $e->getName();
$id = $section->getName() . '_' . $group->getName() . '_' . $fieldPrefix . $e->getName();
if (isset($this->_configData[$path])) {
$data = $this->_configData[$path];
$inherit = false;
} else {
$data = $this->_configRoot->descend($path);
$inherit = true;
}
if ($e->frontend_model) {
$fieldRenderer = Mage::getBlockSingleton((string) $e->frontend_model);
} else {
$fieldRenderer = $this->_defaultFieldRenderer;
}
$fieldRenderer->setForm($this);
$fieldRenderer->setConfigData($this->_configData);
$helperName = $this->_configFields->getAttributeModule($section, $group, $e);
$fieldType = (string) $e->frontend_type ? (string) $e->frontend_type : 'text';
$name = 'groups[' . $group->getName() . '][fields][' . $fieldPrefix . $e->getName() . '][value]';
$label = Mage::helper($helperName)->__($labelPrefix) . ' ' . Mage::helper($helperName)->__((string) $e->label);
$comment = (string) $e->comment ? Mage::helper($helperName)->__((string) $e->comment) : '';
if ($e->backend_model) {
$model = Mage::getModel((string) $e->backend_model);
if (!$model instanceof Mage_Core_Model_Config_Data) {
Mage::throwException('Invalid config field backend model: ' . (string) $e->backend_model);
}
$model->setPath($path)->setValue($data)->afterLoad();
$data = $model->getValue();
}
$field = $fieldset->addField($id, $fieldType, array('name' => $name, 'label' => $label, 'comment' => $comment, 'value' => $data, 'inherit' => $inherit, 'class' => $e->frontend_class, 'field_config' => $e, 'scope' => $this->getScope(), 'scope_id' => $this->getScopeId(), 'can_use_default_value' => $this->canUseDefaultValue((int) $e->show_in_default), 'can_use_website_value' => $this->canUseWebsiteValue((int) $e->show_in_website)));
if (isset($e->validate)) {
$field->addClass($e->validate);
}
if (isset($e->frontend_type) && 'multiselect' === (string) $e->frontend_type && isset($e->can_be_empty)) {
$field->setCanBeEmpty(true);
}
$field->setRenderer($fieldRenderer);
if ($e->source_model) {
$sourceModel = Mage::getSingleton((string) $e->source_model);
if ($sourceModel instanceof Varien_Object) {
$sourceModel->setPath($path);
}
$field->setValues($sourceModel->toOptionArray($fieldType == 'multiselect'));
}
}
}
return $this;
}
示例4: _sortElements
/**
* @param Varien_SimpleXml_Element $group
* @param Varien_Data_Form_Element_Fieldset $fieldset
* @param array $elements
* @return mixed
*/
protected function _sortElements($group, $fieldset, $elements)
{
if ($group->sort_fields && $group->sort_fields->by) {
$fieldset->setSortElementsByAttribute((string) $group->sort_fields->by, $group->sort_fields->direction_desc ? SORT_DESC : SORT_ASC);
} else {
usort($elements, array($this, '_sortForm'));
}
return $elements;
}