本文整理汇总了PHP中Varien_Data_Form_Element_Fieldset::addField方法的典型用法代码示例。如果您正苦于以下问题:PHP Varien_Data_Form_Element_Fieldset::addField方法的具体用法?PHP Varien_Data_Form_Element_Fieldset::addField怎么用?PHP Varien_Data_Form_Element_Fieldset::addField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Varien_Data_Form_Element_Fieldset
的用法示例。
在下文中一共展示了Varien_Data_Form_Element_Fieldset::addField方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: prepareAttributes
/**
* Render required attributes
* @param Varien_Data_Form_Element_Fieldset $fldAttr
* @param Amasty_Banners_Model_Rule $model
*/
protected function prepareAttributes($fldAttr, $model)
{
$hlp = Mage::helper('ambanners');
/*
* Add Empty Fields user for new conditions
*/
$fieldSet = $this->getForm()->addFieldset('attributestmp', array('legend' => $hlp->__('Attribute Tmp')));
$fieldSet->addField('attr_code[][]', 'select', array('label' => $hlp->__('Has attribute'), 'name' => 'attr_code[]', 'values' => $this->getAttributes(), 'onchange' => 'showOptions(this)'));
$fieldSet->addField('attr_value[][]', 'text', array('label' => $hlp->__('Attribute value is'), 'name' => 'attr_value[]'));
$array = $model->getAttributesAsArray();
foreach ($array as $attributeCode => $attributeValue) {
if (empty($attributeCode)) {
continue;
}
if (is_array($attributeValue)) {
foreach ($attributeValue as $i => $value) {
/*
* Add Attribute Names
*/
$elementCode = $attributeCode . '-' . $value . '-' . $i;
$fldAttr->addField('attr_code[' . $elementCode . ']', 'select', array('label' => $hlp->__('Has attribute'), 'name' => 'attr_code[' . $elementCode . ']', 'values' => $this->getAttributes(), 'onchange' => 'showOptions(this)', 'value' => $attributeCode, 'note' => $hlp->__('If attribute is related to configurable products, please make sure that attribute is used in layered navigation'), 'after_element_html' => '<a href="#" onclick="landingRemove(this);return false;" title="' . $hlp->__('Remove') . '">' . $hlp->__('X') . '</a>'));
/*
* Add Attribute Options
*/
$attribute = Mage::getModel('catalog/product')->getResource()->getAttribute($attributeCode);
if ('select' === $attribute->getFrontendInput() || 'multiselect' === $attribute->getFrontendInput()) {
$options = $attribute->getFrontend()->getSelectOptions();
$fldAttr->addField('attr_value[' . $elementCode . ']', 'select', array('label' => $hlp->__('Attribute value is'), 'name' => 'attr_value[' . $elementCode . ']', 'values' => $options, 'value' => $value));
} else {
$fldAttr->addField('attr_value[' . $elementCode . ']', 'text', array('label' => $hlp->__('Attribute value is'), 'name' => 'attr_value[' . $elementCode . ']', 'value' => $value));
}
}
}
}
}
示例2: _addModule
/**
* @param Aitoc_Aitsys_Model_Module $module
* @param Varien_Data_Form_Element_Fieldset $fieldset
*/
protected function _addModule(Aitoc_Aitsys_Model_Module $module, Varien_Data_Form_Element_Fieldset $fieldset)
{
if ($module->isIgnore()) {
return false;
}
$aModule = $module;
$label = $module->getInfo()->getLabel() . ($module->getInfo()->getVersion() ? ' v' . $module->getInfo()->getVersion() : '');
$message = '';
$messageType = 'notice-msg';
$isDemo = false;
if ($this->tool()->platform()->hasDemoMode()) {
$xml = simplexml_load_file(Mage::getBaseDir() . "/aitmodules.xml");
$link = (string) $xml->modules->{$aModule}['key'];
if ($link == '') {
$link = $this->tool()->getAitocUrl();
}
$message = Mage::helper('aitsys')->__("The extension is already enabled on this Demo Magento installation and can't be disabled for security reasons. Please proceed to the next step outlined in the extension's <a href='%s' target='_blank'>User Manual</a> to see how it works.", $link);
$isDemo = true;
} elseif (defined('COMPILER_INCLUDE_PATH')) {
$compilerUrl = version_compare(Mage::getVersion(), '1.5.0.0', '>=') ? Mage::helper('adminhtml')->getUrl('adminhtml/compiler_process/index/') : Mage::helper('adminhtml')->getUrl('compiler/process/index/');
$message = Mage::helper('aitsys')->__('Before activating or deactivating the extension please turn off the compiler at <br /><a href="%s">System > Tools > Compilation</a>', $compilerUrl);
$messageType = 'warning-msg';
} elseif (!$module->getInfo()->isMagentoCompatible()) {
$message = Mage::helper('aitsys/strings')->getString('ER_ENT_HASH');
} elseif (!$module->getAccess()) {
$message = Mage::helper('aitsys')->__('File does not have write permissions: %s', $aModule['file']);
$messageType = 'error-msg';
}
if ($module->getInfo()->getSerial()) {
$info = 'S/N: ' . $module->getInfo()->getSerial();
}
if ($aModule['key'] == 'Aitoc_Common') {
$info = 'Used by other AITOC\'s modules. Do not disable.';
}
if ($message && $messageType != 'notice-msg' || $isDemo) {
$field = $fieldset->addField('ignore_' . $aModule['key'], 'note', array('name' => 'ignore[' . $aModule['key'] . ']', 'label' => $label, 'info' => empty($info) ? '' : $info, 'note' => '<ul class="messages"><li class="' . $messageType . '"><ul><li>' . $message . '</li></ul></li></ul>', 'module' => $module));
if (!$isDemo) {
$field->setRenderer($this->_elementRenderer);
}
return;
}
$fieldset->addField('hidden_enable_' . $aModule['key'], 'hidden', array('name' => 'enable[' . $aModule['key'] . ']', 'value' => 0));
$fieldset->addField('enable_' . $aModule['key'], 'checkbox', array('name' => ($module->getAccess() ? 'enable' : 'ignore') . '[' . $aModule['key'] . ']', 'label' => $label, 'value' => 1, 'checked' => $aModule['value'], 'note' => $message ? '<ul class="messages"><li class="' . $messageType . '"><ul><li>' . $message . '</li></ul></li></ul>' : '', 'info' => empty($info) ? '' : $info, 'module' => $module))->setRenderer($this->_elementRenderer);
}
示例3: addField
/**
* @param Varien_Data_Form_Element_Fieldset $fieldset
* @param string $id
* @param string $type
* @param array $options
* @return Varien_Data_Form_Element_Abstract
*/
public function addField($fieldset, $id, $type, $options)
{
/** @noinspection PhpParamsInspection */
$field = $fieldset->addField($id, $type, $options);
if (isset($options['values'])) {
$field->setValues($options['values']);
}
$field->setRenderer($this->getFieldRenderer());
return $field;
}
示例4: createFieldConditions
/**
* @param Varien_Data_Form_Element_Fieldset $fieldset
* @return Varien_Data_Form_Element_Abstract
*/
private function createFieldConditions(Varien_Data_Form_Element_Fieldset $fieldset)
{
/** @var Varien_Data_Form_Element_Abstract $result */
$result = $fieldset->addField('conditions', 'text', array('name' => 'conditions', 'label' => Mage::helper('catalogrule')->__('Conditions'), 'title' => Mage::helper('catalogrule')->__('Conditions'), 'required' => true));
/** @var Mage_Rule_Block_Conditions $blockRuleConditions */
$blockRuleConditions = Mage::getBlockSingleton('rule/conditions');
$result->setData('rule', $this->getRule());
$result->setRenderer($blockRuleConditions);
df_assert($result instanceof Varien_Data_Form_Element_Abstract);
return $result;
}
示例5: _addFieldsToFieldset
/**
* This method makes life a little easier for us by pre-populating
* fields with $_POST data where applicable and wraps our post data in
* 'newsData' so we can easily separate all relevant information in
* the controller. You can of course omit this method entirely and call
* the $fieldset->addField() method directly.
*/
protected function _addFieldsToFieldset(Varien_Data_Form_Element_Fieldset $fieldset, $fields)
{
$requestData = new Varien_Object($this->getRequest()->getPost('newsData'));
foreach ($fields as $name => $_data) {
if ($requestValue = $requestData->getData($name)) {
$_data['value'] = $requestValue;
}
// wrap all fields with newsData group
$_data['name'] = "newsData[{$name}]";
// generally label and title always the same
$_data['title'] = $_data['label'];
// finally call vanilla functionality to add field
$fieldset->addField($name, $_data['input'], $_data);
}
return $this;
}
示例6: addField
/**
* @param Varien_Data_Form_Element_Fieldset $fieldset
* @param string $id
* @param string $type
* @param array $options
* @return Varien_Data_Form_Element_Abstract
*/
public function addField($fieldset, $id, $type, $options)
{
if (isset($options['renderer'])) {
$renderer = $this->getLayout()->getBlockSingleton($options['renderer']);
unset($options['renderer']);
} else {
$renderer = $this->getFieldRenderer();
}
/** @noinspection PhpParamsInspection */
$field = $fieldset->addField($id, $type, $options);
if (isset($options['values'])) {
$field->setValues($options['values']);
}
$field->setRenderer($renderer);
return $field;
}
示例7: _addFieldsToFieldset
protected function _addFieldsToFieldset(Varien_Data_Form_Element_Fieldset $fieldset, $fields)
{
$requestData = new Varien_Object($this->getRequest()->getPost('accordionData'));
foreach ($fields as $name => $_data) {
if ($requestValue = $requestData->getData($name)) {
$_data['value'] = $requestValue;
}
# code...
$_data['name'] = "accordionData[{$name}]";
$_data['title'] = $_data['label'];
if (!array_key_exists('value', $_data)) {
$_data['value'] = $this->_getAccordion()->getData($name);
}
$fieldset->addField($name, $_data['input'], $_data);
}
return $this;
}
示例8: _addFieldsToFieldset
/**
* This method makes life a little easier for us by pre-populating
* fields with $_POST data where applicable and wrapping our post data
* in 'brandData' so that we can easily separate all relevant information
* in the controller. You could of course omit this method entirely
* and call the $fieldset->addField() method directly.
* @return self
*/
protected function _addFieldsToFieldset(Varien_Data_Form_Element_Fieldset $fieldset, $fields)
{
foreach ($fields as $name => $_data) {
// Wrap all fields with brandData group.
$_data['name'] = "configData[{$name}]";
// Generally, label and title are always the same.
$_data['title'] = $_data['label'];
// If no new value exists, use the existing data.
if (!array_key_exists('value', $_data)) {
$_data['value'] = $this->_getValue()->getData($name);
}
if ($name == "test_mode") {
$_data['checked'] = $this->_getValue()->getData($name);
}
// Finally, call vanilla functionality to add field.
$fieldset->addField($name, $_data['input'], $_data);
}
return $this;
}
示例9: _addFieldsToFieldset
/**
* This method makes life a little easier for us by pre-populating
* fields with $_POST data where applicable and wrapping our post data
* in 'commentData' so that we can easily separate all relevant information
* in the controller. You could of course omit this method entirely
* and call the $fieldset->addField() method directly.
*/
protected function _addFieldsToFieldset(Varien_Data_Form_Element_Fieldset $fieldset, $fields)
{
$requestData = new Varien_Object($this->getRequest()->getPost('commentData'));
foreach ($fields as $name => $_data) {
if ($requestValue = $requestData->getData($name)) {
$_data['value'] = $requestValue;
}
// Wrap all fields with commentData group.
$_data['name'] = "commentData[{$name}]";
// Generally, label and title are always the same.
$_data['title'] = $_data['label'];
// If no new value exists, use the existing comment data.
if (!array_key_exists('value', $_data)) {
$_data['value'] = $this->_getComment()->getData($name);
}
// Finally, call vanilla functionality to add field.
$fieldset->addField($name, $_data['input'], $_data);
}
return $this;
}
示例10: _addFieldsToFieldset
/**
* This method makes life a little easier for us by pre-populating
* fields with $_POST data where applicable and wraps our post data in
* 'brandData' so we can easily separate all relevant information in
* the controller. You can of course omit this method entirely and call
* the $fieldset->addField() method directly.
*/
protected function _addFieldsToFieldset(Varien_Data_Form_Element_Fieldset $fieldset, $fields)
{
$requestData = new Varien_Object($this->getRequest()->getPost('mappingData'));
foreach ($fields as $name => $_data) {
if ($requestValue = $requestData->getData($name)) {
$_data['value'] = $requestValue;
}
// wrap all fields with brandData group
$_data['name'] = "mappingData[{$name}]";
// generally label and title always the same
$_data['title'] = $_data['label'];
// if no new value exists, use existing brand data
if (!array_key_exists('value', $_data)) {
$_data['value'] = $this->_getBrand()->getData($name);
}
// finally call vanilla functionality to add field
$fieldset->addField($name, $_data['input'], $_data);
}
return $this;
}
示例11: 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;
}
示例12: _addNewUserPasswordFields
/**
* Add password creation fields in new user form
*
* @param Varien_Data_Form_Element_Fieldset $fieldset
*/
protected function _addNewUserPasswordFields(Varien_Data_Form_Element_Fieldset $fieldset)
{
$fieldset->addField('password', 'password', array('name' => 'password', 'label' => Mage::helper('Mage_User_Helper_Data')->__('Password'), 'id' => 'customer_pass', 'title' => Mage::helper('Mage_User_Helper_Data')->__('Password'), 'class' => 'input-text required-entry validate-admin-password', 'required' => true));
$fieldset->addField('confirmation', 'password', array('name' => 'password_confirmation', 'label' => Mage::helper('Mage_User_Helper_Data')->__('Password Confirmation'), 'id' => 'confirmation', 'title' => Mage::helper('Mage_User_Helper_Data')->__('Password Confirmation'), 'class' => 'input-text required-entry validate-cpassword', 'required' => true));
}
示例13: _prepareStoreElement
/**
* Prepare store element
*
* @param Varien_Data_Form_Element_Fieldset $fieldset
*/
protected function _prepareStoreElement($fieldset)
{
// get store switcher or a hidden field with it's id
if (Mage::app()->isSingleStoreMode()) {
$fieldset->addField('store_id', 'hidden', array('name' => 'store_id', 'value' => Mage::app()->getStore(true)->getId()), 'id_path');
} else {
/** @var $renderer Mage_Adminhtml_Block_Store_Switcher_Form_Renderer_Fieldset_Element */
$renderer = $this->getLayout()->createBlock('Mage_Adminhtml_Block_Store_Switcher_Form_Renderer_Fieldset_Element');
$storeElement = $fieldset->addField('store_id', 'select', array('label' => Mage::helper('Mage_Adminhtml_Helper_Data')->__('Store'), 'title' => Mage::helper('Mage_Adminhtml_Helper_Data')->__('Store'), 'name' => 'store_id', 'required' => true, 'values' => $this->_getRestrictedStoresList(), 'disabled' => $this->_getModel()->getIsSystem(), 'value' => $this->_formValues['store_id']), 'id_path');
$storeElement->setRenderer($renderer);
}
}
示例14: _addRendererField
/**
* Add field to form based on parameter configuration
*
* @param Varien_Data_Form_Element_Fieldset $fieldset
* @param Varien_Object $parameter
* @return Varien_Data_Form_Element_Abstract
*/
protected function _addRendererField($fieldset, $parameter)
{
$form = $this->getForm();
// Prepare element data with values (either from request of from default values)
$fieldName = $parameter->getKey();
$data = array('name' => $form->addSuffixToName($fieldName, 'parameters'), 'label' => $this->_translationHelper->__($parameter->getLabel()), 'required' => $parameter->getRequired(), 'class' => 'renderer-option', 'note' => $this->_translationHelper->__($parameter->getDescription()));
if ($values = $this->getRendererParams()) {
$data['value'] = isset($values[$fieldName]) ? $values[$fieldName] : '';
} else {
$data['value'] = $parameter->getValue();
// Prepare unique ID value
if ($fieldName == 'unique_id' && $data['value'] == '') {
$data['value'] = md5(microtime(1));
}
}
// Prepare element dropdown values
if ($values = $parameter->getValues()) {
// Dropdown options are specified in configuration
$data['values'] = array();
foreach ($values as $option) {
$data['values'][] = array('label' => $this->_translationHelper->__($option['label']), 'value' => $option['value']);
}
} elseif ($sourceModel = $parameter->getSourceModel()) {
// Otherwise, a source model is specified
if (is_array($sourceModel)) {
// TODO check if invalid model / method ?
$data['values'] = call_user_func(array(Mage::getModel($sourceModel['model']), $sourceModel['method']));
} else {
$data['values'] = Mage::getModel($sourceModel)->toOptionArray();
}
}
// Prepare field type or renderer
$fieldRenderer = null;
$fieldType = $parameter->getType();
if (!$parameter->getVisible()) {
// Hidden element
$fieldType = 'hidden';
} elseif (false !== strpos($fieldType, '/')) {
// Just an element renderer
$fieldRenderer = $this->getLayout()->createBlock($fieldType);
$fieldType = $this->_defaultElementType;
}
// Instantiate field and render html
$field = $fieldset->addField($this->getFieldsetHtmlId() . '_' . $fieldName, $fieldType, $data);
if ($fieldRenderer) {
$field->setRenderer($fieldRenderer);
}
// Extra html preparations
if ($helper = $parameter->getHelperBlock()) {
$helperBlock = $this->getLayout()->createBlock($helper->getType(), '', $helper->getData());
if ($helperBlock instanceof Varien_Object) {
$helperBlock->setConfig($helper->getData())->setFieldsetId($fieldset->getId())->setTranslationHelper($this->_translationHelper)->prepareElementHtml($field);
}
}
// Dependencies from other fields
$dependenceBlock = $this->getChild('form_after');
$dependenceBlock->addFieldMap($field->getId(), $fieldName);
if ($parameter->getDepends()) {
foreach ($parameter->getDepends() as $from => $row) {
$values = isset($row['values']) ? array_values($row['values']) : (string) $row['value'];
$dependenceBlock->addFieldDependence($fieldName, $from, $values);
}
}
return $field;
}
示例15: _prepareVisibleFields
/**
* Prepare form fieldset
* All fields are visible
*
* @param Varien_Data_Form_Element_Fieldset $fieldset
*
* @return Mage_Adminhtml_Block_Sales_Order_Create_Giftmessage_Form
*/
protected function _prepareVisibleFields(Varien_Data_Form_Element_Fieldset $fieldset)
{
$fieldset->addField('sender', 'text', array('name' => $this->_getFieldName('sender'), 'label' => Mage::helper('sales')->__('From'), 'required' => $this->getMessage()->getMessage() ? true : false));
$fieldset->addField('recipient', 'text', array('name' => $this->_getFieldName('recipient'), 'label' => Mage::helper('sales')->__('To'), 'required' => $this->getMessage()->getMessage() ? true : false));
$fieldset->addField('message', 'textarea', array('name' => $this->_getFieldName('message'), 'label' => Mage::helper('sales')->__('Message'), 'rows' => '5', 'cols' => '20'));
return $this;
}