本文整理汇总了PHP中Magento\Framework\Data\Form类的典型用法代码示例。如果您正苦于以下问题:PHP Form类的具体用法?PHP Form怎么用?PHP Form使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Form类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: _formPostInit
/**
* Form post init
*
* @param \Magento\Framework\Data\Form $form
* @return \Magento\UrlRedirect\Block\Cms\Page\Edit\Form
*/
protected function _formPostInit($form)
{
$cmsPage = $this->_getCmsPage();
$form->setAction($this->_adminhtmlData->getUrl('adminhtml/*/save', array('id' => $this->_getModel()->getId(), 'cms_page' => $cmsPage->getId())));
// Fill request path and target path elements
/** @var $requestPath \Magento\Framework\Data\Form\Element\AbstractElement */
$requestPath = $this->getForm()->getElement('request_path');
/** @var $targetPath \Magento\Framework\Data\Form\Element\AbstractElement */
$targetPath = $this->getForm()->getElement('target_path');
$model = $this->_getModel();
/** @var $cmsPageUrlrewrite \Magento\Cms\Model\Page\Urlrewrite */
$cmsPageUrlrewrite = $this->_urlRewriteFactory->create();
if (!$model->getId()) {
$sessionData = $this->_getSessionData();
if (!isset($sessionData['request_path'])) {
$requestPath->setValue($cmsPageUrlrewrite->generateRequestPath($cmsPage));
}
$targetPath->setValue($cmsPageUrlrewrite->generateTargetPath($cmsPage));
$disablePaths = true;
} else {
$cmsPageUrlrewrite->load($this->_getModel()->getId(), 'url_rewrite_id');
$disablePaths = $cmsPageUrlrewrite->getId() > 0;
}
if ($disablePaths) {
$targetPath->setData('disabled', true);
}
return $this;
}
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:34,代码来源:Form.php
示例2: _prepareStoreFieldset
/**
* Prepare group specific fieldset
*
* @param \Magento\Framework\Data\Form $form
* @return void
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
protected function _prepareStoreFieldset(\Magento\Framework\Data\Form $form)
{
$groupModel = $this->_coreRegistry->registry('store_data');
$postData = $this->_coreRegistry->registry('store_post_data');
if ($postData) {
$groupModel->setData($postData['group']);
}
$fieldset = $form->addFieldset('group_fieldset', ['legend' => __('Store Information')]);
$storeAction = $this->_coreRegistry->registry('store_action');
if ($storeAction == 'edit' || $storeAction == 'add') {
$websites = $this->_websiteFactory->create()->getCollection()->toOptionArray();
$fieldset->addField('group_website_id', 'select', ['name' => 'group[website_id]', 'label' => __('Web Site'), 'value' => $groupModel->getWebsiteId(), 'values' => $websites, 'required' => true, 'disabled' => $groupModel->isReadOnly()]);
if ($groupModel->getId() && $groupModel->getWebsite()->getDefaultGroupId() == $groupModel->getId()) {
if ($groupModel->getWebsite()->getIsDefault() || $groupModel->getWebsite()->getGroupsCount() == 1) {
$form->getElement('group_website_id')->setDisabled(true);
$fieldset->addField('group_hidden_website_id', 'hidden', ['name' => 'group[website_id]', 'no_span' => true, 'value' => $groupModel->getWebsiteId()]);
} else {
$fieldset->addField('group_original_website_id', 'hidden', ['name' => 'group[original_website_id]', 'no_span' => true, 'value' => $groupModel->getWebsiteId()]);
}
}
}
$fieldset->addField('group_name', 'text', ['name' => 'group[name]', 'label' => __('Name'), 'value' => $groupModel->getName(), 'required' => true, 'disabled' => $groupModel->isReadOnly()]);
$categories = $this->_category->toOptionArray();
$fieldset->addField('group_root_category_id', 'select', ['name' => 'group[root_category_id]', 'label' => __('Root Category'), 'value' => $groupModel->getRootCategoryId(), 'values' => $categories, 'required' => true, 'disabled' => $groupModel->isReadOnly()]);
if ($this->_coreRegistry->registry('store_action') == 'edit') {
$storeActive = 1;
$stores = $this->_storeFactory->create()->getCollection()->addGroupFilter($groupModel->getId())->addStatusFilter($storeActive)->toOptionArray();
$fieldset->addField('group_default_store_id', 'select', ['name' => 'group[default_store_id]', 'label' => __('Default Store View'), 'value' => $groupModel->getDefaultStoreId(), 'values' => $stores, 'required' => false, 'disabled' => $groupModel->isReadOnly()]);
}
$fieldset->addField('group_group_id', 'hidden', ['name' => 'group[group_id]', 'no_span' => true, 'value' => $groupModel->getId()]);
}
开发者ID:Doability,项目名称:magento2dev,代码行数:38,代码来源:Group.php
示例3: _prepareStoreFieldset
/**
* Prepare store specific fieldset
*
* @param \Magento\Framework\Data\Form $form
* @return void
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
protected function _prepareStoreFieldset(\Magento\Framework\Data\Form $form)
{
$storeModel = $this->_coreRegistry->registry('store_data');
$postData = $this->_coreRegistry->registry('store_post_data');
if ($postData) {
$storeModel->setData($postData['store']);
}
$fieldset = $form->addFieldset('store_fieldset', array('legend' => __('Store View Information')));
$storeAction = $this->_coreRegistry->registry('store_action');
if ($storeAction == 'edit' || $storeAction == 'add') {
$fieldset->addField('store_group_id', 'select', array('name' => 'store[group_id]', 'label' => __('Store'), 'value' => $storeModel->getGroupId(), 'values' => $this->_getStoreGroups(), 'required' => true, 'disabled' => $storeModel->isReadOnly()));
if ($storeModel->getId() && $storeModel->getGroup()->getDefaultStoreId() == $storeModel->getId()) {
if ($storeModel->getGroup() && $storeModel->getGroup()->getStoresCount() > 1) {
$form->getElement('store_group_id')->setDisabled(true);
$fieldset->addField('store_hidden_group_id', 'hidden', array('name' => 'store[group_id]', 'no_span' => true, 'value' => $storeModel->getGroupId()));
} else {
$fieldset->addField('store_original_group_id', 'hidden', array('name' => 'store[original_group_id]', 'no_span' => true, 'value' => $storeModel->getGroupId()));
}
}
}
$fieldset->addField('store_name', 'text', array('name' => 'store[name]', 'label' => __('Name'), 'value' => $storeModel->getName(), 'required' => true, 'disabled' => $storeModel->isReadOnly()));
$fieldset->addField('store_code', 'text', array('name' => 'store[code]', 'label' => __('Code'), 'value' => $storeModel->getCode(), 'required' => true, 'disabled' => $storeModel->isReadOnly()));
$fieldset->addField('store_is_active', 'select', array('name' => 'store[is_active]', 'label' => __('Status'), 'value' => $storeModel->getIsActive(), 'options' => array(0 => __('Disabled'), 1 => __('Enabled')), 'required' => true, 'disabled' => $storeModel->isReadOnly()));
$fieldset->addField('store_sort_order', 'text', array('name' => 'store[sort_order]', 'label' => __('Sort Order'), 'value' => $storeModel->getSortOrder(), 'required' => false, 'disabled' => $storeModel->isReadOnly()));
$fieldset->addField('store_is_default', 'hidden', array('name' => 'store[is_default]', 'no_span' => true, 'value' => $storeModel->getIsDefault()));
$fieldset->addField('store_store_id', 'hidden', array('name' => 'store[store_id]', 'no_span' => true, 'value' => $storeModel->getId(), 'disabled' => $storeModel->isReadOnly()));
}
开发者ID:aiesh,项目名称:magento2,代码行数:34,代码来源:Store.php
示例4: _addThemeFieldset
/**
* Add theme fieldset
*
* @param \Magento\Framework\Data\Form $form
* @param array $formData
* @param ThemeInterface $theme
* @return $this
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
protected function _addThemeFieldset($form, $formData, ThemeInterface $theme)
{
$themeFieldset = $form->addFieldset('theme', ['legend' => __('Theme Settings')]);
$this->_addElementTypes($themeFieldset);
if (isset($formData['theme_id'])) {
$themeFieldset->addField('theme_id', 'hidden', ['name' => 'theme_id']);
}
/** @var \Magento\Theme\Model\Theme\Collection $themesCollections */
$themesCollections = $this->_objectManager->create('Magento\\Theme\\Model\\Theme\\Collection');
/** @var \Magento\Framework\Json\Helper\Data $helper */
$helper = $this->_objectManager->get('Magento\\Framework\\Json\\Helper\\Data');
$onChangeScript = sprintf('parentThemeOnChange(this.value, %s)', str_replace('"', '\'', $helper->jsonEncode($this->_getDefaultsInherited($themesCollections->addDefaultPattern()))));
/** @var ThemeInterface $parentTheme */
$parentTheme = $this->_objectManager->create('Magento\\Framework\\View\\Design\\ThemeInterface');
if (!empty($formData['parent_id'])) {
$parentTheme->load($formData['parent_id']);
}
if ($this->_getCurrentTheme()->isObjectNew()) {
$themeFieldset->addField('parent_id', 'select', ['label' => __('Parent Theme'), 'title' => __('Parent Theme'), 'name' => 'parent_id', 'values' => $themesCollections->toOptionArray(!$parentTheme->getId()), 'required' => true, 'class' => 'no-changes', 'onchange' => $onChangeScript]);
} elseif (!empty($formData['parent_id'])) {
$themeFieldset->addField('parent_title', 'note', ['label' => __('Parent Theme'), 'title' => __('Parent Theme'), 'name' => 'parent_title', 'text' => $parentTheme->getId() ? $parentTheme->getThemeTitle() : '']);
}
if (!empty($formData['theme_path'])) {
$themeFieldset->addField('theme_path', 'label', ['label' => __('Theme Path'), 'title' => __('Theme Path'), 'name' => 'theme_code']);
}
$themeFieldset->addField('theme_title', $this->_getFieldTextType(), ['label' => __('Theme Title'), 'title' => __('Theme Title'), 'name' => 'theme_title', 'required' => $this->_isFieldAttrRequired()]);
if ($this->_isThemeEditable) {
$themeFieldset->addField('preview_image', 'image', ['label' => __('Theme Preview Image'), 'title' => __('Theme Preview Image'), 'name' => 'preview', 'required' => false, 'note' => $this->_getPreviewImageNote(), 'theme' => $theme]);
} elseif ($theme->hasPreviewImage()) {
$themeFieldset->addField('preview_image', 'note', ['label' => __('Theme Preview Image'), 'title' => __('Theme Preview Image'), 'name' => 'preview', 'after_element_html' => '<a href="' . $theme->getThemeImage()->getPreviewImageUrl() . '" onclick="imagePreview(\'theme_preview_image\'); return false;">' . '<img width="50" src="' . $theme->getThemeImage()->getPreviewImageUrl() . '" id="theme_preview_image" /></a>']);
}
return $this;
}
开发者ID:shabbirvividads,项目名称:magento2,代码行数:42,代码来源:General.php
示例5: addGoogleoptimizerFields
/**
* Prepare form
*
* @param DataForm $form
* @param ModelCode|null $experimentCodeModel
* @param string $formName
* @return void
*/
public function addGoogleoptimizerFields(DataForm $form, ModelCode $experimentCodeModel = null, $formName = '')
{
$fieldset = $form->addFieldset('googleoptimizer_fields', ['legend' => __('Google Analytics Content Experiments Code')]);
$fieldset->addField('experiment_script', 'textarea', ['name' => 'experiment_script', 'label' => __('Experiment Code'), 'value' => $experimentCodeModel ? $experimentCodeModel->getExperimentScript() : '', 'class' => 'textarea googleoptimizer', 'required' => false, 'note' => __('Experiment code should be added to the original page only.'), 'data-form-part' => $formName]);
$fieldset->addField('code_id', 'hidden', ['name' => 'code_id', 'value' => $experimentCodeModel ? $experimentCodeModel->getCodeId() : '', 'required' => false, 'data-form-part' => $formName]);
$form->setFieldNameSuffix('google_experiment');
}
开发者ID:Doability,项目名称:magento2dev,代码行数:15,代码来源:Form.php
示例6: _formPostInit
/**
* Form post init
*
* @param \Magento\Framework\Data\Form $form
* @return $this
*/
protected function _formPostInit($form)
{
$form->setAction($this->_adminhtmlData->getUrl('adminhtml/*/save', array('id' => $this->_getModel()->getId(), 'product' => $this->_getProduct()->getId(), 'category' => $this->_getCategory()->getId())));
/** @var $requestPath \Magento\Framework\Data\Form\Element\AbstractElement */
$requestPath = $this->getForm()->getElement('request_path');
/** @var $targetPath \Magento\Framework\Data\Form\Element\AbstractElement */
$targetPath = $this->getForm()->getElement('target_path');
$model = $this->_getModel();
$disablePaths = false;
if (!$model->getId()) {
$product = null;
$category = null;
if ($this->_getProduct()->getId()) {
$product = $this->_getProduct();
$category = $this->_getCategory();
} elseif ($this->_getCategory()->getId()) {
$category = $this->_getCategory();
}
if ($product || $category) {
$sessionData = $this->_getSessionData();
if (!isset($sessionData['request_path'])) {
$requestPath->setValue($this->_catalogUrl->generatePath('request', $product, $category, ''));
}
$targetPath->setValue($this->_catalogUrl->generatePath('target', $product, $category));
$disablePaths = true;
}
} else {
$disablePaths = in_array($model->getEntityType(), [UrlRedirect::ENTITY_TYPE_PRODUCT, UrlRedirect::ENTITY_TYPE_CATEGORY, UrlRedirect::ENTITY_TYPE_CMS_PAGE]);
}
if ($disablePaths) {
$targetPath->setData('disabled', true);
}
return $this;
}
开发者ID:aiesh,项目名称:magento2,代码行数:40,代码来源:Form.php
示例7: __construct
/**
* @param ContextInterface $context
* @param FormFactory $formFactory
* @param ConfigInterface $wysiwygConfig
* @param array $components
* @param array $data
* @param array $config
*/
public function __construct(ContextInterface $context, FormFactory $formFactory, ConfigInterface $wysiwygConfig, array $components = [], array $data = [], array $config = [])
{
$wysiwygConfigData = isset($config['wysiwygConfigData']) ? $config['wysiwygConfigData'] : [];
$this->form = $formFactory->create();
$this->editor = $this->form->addField($context->getNamespace() . '_' . $data['name'], 'Magento\\Framework\\Data\\Form\\Element\\Editor', ['force_load' => true, 'rows' => 20, 'name' => $data['name'], 'config' => $wysiwygConfig->getConfig($wysiwygConfigData), 'wysiwyg' => isset($config['wysiwyg']) ? $config['wysiwyg'] : null]);
$data['config']['content'] = $this->editor->getElementHtml();
parent::__construct($context, $components, $data);
}
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:16,代码来源:Wysiwyg.php
示例8: testAddFields
/**
* @dataProvider dataAddFields
*/
public function testAddFields($expected)
{
$this->moduleManagerMock->expects($this->once())->method('isOutputEnabled')->willReturn($expected['isOutputEnabled']);
$this->eventObserverMock->expects($this->exactly($expected['methods_count']))->method('getForm')->willReturn($this->formMock);
$element = $this->getMock('Magento\\Framework\\Data\\Form\\Element\\AbstractElement', [], [], '', false);
$this->formMock->expects($this->exactly($expected['methods_count']))->method('getElement')->with('base_fieldset')->willReturn($element);
$element->expects($this->exactly($expected['addField_count']))->method('addField');
$this->yesNoMock->expects($this->exactly($expected['yesno_count']))->method('toOptionArray');
$this->observerMock->execute($this->eventObserverMock);
}
开发者ID:Doability,项目名称:magento2dev,代码行数:13,代码来源:AddFieldsToAttributeObserverTest.php
示例9: testLock
/**
* @covers \Magento\Eav\Block\Adminhtml\Attribute\PropertyLocker::lock
*/
public function testLock()
{
$lockedFields = ['is_searchable' => 'is_searchable', 'is_filterable' => 'is_filterable'];
$this->attributeMock->expects($this->once())->method('getId')->willReturn(1);
$this->attributeConfigMock->expects($this->once())->method('getLockedFields')->willReturn($lockedFields);
$elementMock = $this->getMockBuilder('\\Magento\\Framework\\Data\\Form\\Element\\AbstractElement')->setMethods(['setDisabled', 'setReadonly'])->disableOriginalConstructor()->getMockForAbstractClass();
$elementMock->expects($this->exactly(2))->method('setDisabled');
$elementMock->expects($this->exactly(2))->method('setReadonly');
$this->formMock->expects($this->exactly(2))->method('getElement')->willReturn($elementMock);
$this->object->lock($this->formMock);
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:14,代码来源:PropertyLockerTest.php
示例10: setUp
protected function setUp()
{
parent::setUp();
$this->formFactoryMock = $this->getMockBuilder(FormFactory::class)->disableOriginalConstructor()->setMethods(['create'])->getMock();
$this->formMock = $this->getMockBuilder(Form::class)->disableOriginalConstructor()->getMock();
$this->wysiwygConfig = $this->getMockBuilder(ConfigInterface::class)->getMockForAbstractClass();
$this->editorMock = $this->getMockBuilder(Editor::class)->disableOriginalConstructor()->getMock();
$this->formFactoryMock->expects($this->any())->method('create')->willReturn($this->formMock);
$this->formMock->expects($this->once())->method('addField')->willReturn($this->editorMock);
$this->editorMock->expects($this->once())->method('getElementHtml');
}
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:11,代码来源:WysiwygTest.php
示例11: lock
/**
* @param \Magento\Framework\Data\Form $form
* @return void
*/
public function lock(\Magento\Framework\Data\Form $form)
{
/** @var \Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attributeObject */
$attributeObject = $this->registry->registry('entity_attribute');
if ($attributeObject->getId()) {
foreach ($this->attributeConfig->getLockedFields($attributeObject) as $field) {
if ($element = $form->getElement($field)) {
$element->setDisabled(1);
$element->setReadonly(1);
}
}
}
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:17,代码来源:PropertyLocker.php
示例12: setForm
/**
* Set form object
*
* @param \Magento\Framework\Data\Form $form
* @return $this
*/
public function setForm(\Magento\Framework\Data\Form $form)
{
$this->_form = $form;
$this->_form->setParent($this);
$this->_form->setBaseUrl($this->_urlBuilder->getBaseUrl());
return $this;
}
开发者ID:aiesh,项目名称:magento2,代码行数:13,代码来源:Form.php
示例13: _prepareLayout
/**
* Prepare global layout
* Add renderers to \Magento\Framework\Data\Form
*
* @return $this
*/
protected function _prepareLayout()
{
parent::_prepareLayout();
\Magento\Framework\Data\Form::setElementRenderer($this->getLayout()->createBlock('Magento\\Backend\\Block\\Widget\\Form\\Renderer\\Element', $this->getNameInLayout() . '_element'));
\Magento\Framework\Data\Form::setFieldsetRenderer($this->getLayout()->createBlock('Magento\\Backend\\Block\\Widget\\Form\\Renderer\\Fieldset', $this->getNameInLayout() . '_fieldset'));
\Magento\Framework\Data\Form::setFieldsetElementRenderer($this->getLayout()->createBlock('Magento\\Backend\\Block\\Widget\\Form\\Renderer\\Fieldset\\Element', $this->getNameInLayout() . '_fieldset_element'));
return $this;
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:14,代码来源:AbstractForm.php
示例14: testAddEllement
public function testAddEllement()
{
$this->_factoryCollectionMock->expects($this->any())->method('create')->will($this->returnValue($this->allElementsMock));
$this->_form = new Form($this->_factoryElementMock, $this->_factoryCollectionMock, $this->_formKeyMock);
$this->elementMock->expects($this->any())->method('getId')->will($this->returnValue('element_id'));
$this->allElementsMock->expects($this->exactly(2))->method('add')->with($this->elementMock, false);
$this->_form->addElement($this->elementMock);
}
开发者ID:Atlis,项目名称:docker-magento2,代码行数:8,代码来源:FormTest.php
示例15: _formPostInit
/**
* Form post init
*
* @param \Magento\Framework\Data\Form $form
* @return \Magento\UrlRewrite\Block\Cms\Page\Edit\Form
*/
protected function _formPostInit($form)
{
$cmsPage = $this->_getCmsPage();
$form->setAction($this->_adminhtmlData->getUrl('adminhtml/*/save', ['id' => $this->_getModel()->getId(), 'cms_page' => $cmsPage->getId()]));
// Fill request path and target path elements
/** @var $requestPath \Magento\Framework\Data\Form\Element\AbstractElement */
$requestPath = $this->getForm()->getElement('request_path');
/** @var $targetPath \Magento\Framework\Data\Form\Element\AbstractElement */
$targetPath = $this->getForm()->getElement('target_path');
$model = $this->_getModel();
if (!$model->getId()) {
$sessionData = $this->_getSessionData();
if (!isset($sessionData['request_path'])) {
$requestPath->setValue($this->cmsPageUrlPathGenerator->getUrlPath($cmsPage));
}
$targetPath->setValue($this->cmsPageUrlPathGenerator->getCanonicalUrlPath($cmsPage));
}
$targetPath->setData('disabled', true);
return $this;
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:26,代码来源:Form.php
示例16: _addStoresFieldset
/**
* Add Fieldset with Store labels
*
* @param \Magento\Sales\Model\Order\Status $model
* @param \Magento\Framework\Data\Form $form
* @return void
*/
protected function _addStoresFieldset($model, $form)
{
$labels = $model ? $model->getStoreLabels() : [];
$fieldset = $form->addFieldset('store_labels_fieldset', ['legend' => __('Store View Specific Labels'), 'class' => 'store-scope']);
$renderer = $this->getLayout()->createBlock('Magento\\Backend\\Block\\Store\\Switcher\\Form\\Renderer\\Fieldset');
$fieldset->setRenderer($renderer);
foreach ($this->_storeManager->getWebsites() as $website) {
$fieldset->addField("w_{$website->getId()}_label", 'note', ['label' => $website->getName(), 'fieldset_html_class' => 'website']);
foreach ($website->getGroups() as $group) {
$stores = $group->getStores();
if (count($stores) == 0) {
continue;
}
$fieldset->addField("sg_{$group->getId()}_label", 'note', ['label' => $group->getName(), 'fieldset_html_class' => 'store-group']);
foreach ($stores as $store) {
$fieldset->addField("store_label_{$store->getId()}", 'text', ['name' => 'store_labels[' . $store->getId() . ']', 'required' => false, 'label' => $store->getName(), 'value' => isset($labels[$store->getId()]) ? $labels[$store->getId()] : '', 'fieldset_html_class' => 'store']);
}
}
}
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:27,代码来源:Form.php
示例17: testElementOperations
public function testElementOperations()
{
$buttonElement = $this->getMockBuilder('Magento\\Framework\\Data\\Form\\Element\\Button')->disableOriginalConstructor()->getMock();
$buttonElement->expects($this->any())->method('getId')->will($this->returnValue('1'));
$buttonElement->expects($this->any())->method('getName')->will($this->returnValue('Hero'));
$this->_form->addElement($buttonElement);
$this->_form->addElementToCollection($buttonElement);
$this->_form->addValues(['1', '2', '3']);
$this->_form->setValues(['4', '5', '6']);
$this->_form->addFieldNameSuffix('abc123');
$this->_form->removeField($buttonElement->getId());
$this->assertSame($this->_form->checkElementId($buttonElement->getId()), true);
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:13,代码来源:FormTest.php
示例18: setForm
/**
* Set form object
*
* @param \Magento\Framework\Data\Form $form
* @return $this
*/
public function setForm(\Magento\Framework\Data\Form $form)
{
$this->_form = $form;
$this->_form->setParent($this);
$this->_form->setBaseUrl($this->_urlBuilder->getBaseUrl());
$customAttributes = $this->getData('custom_attributes');
if (is_array($customAttributes)) {
foreach ($customAttributes as $key => $value) {
$this->_form->addCustomAttribute($key, $value);
}
}
return $this;
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:19,代码来源:Form.php
示例19: _prepareStoreFieldset
/**
* Prepare website specific fieldset
*
* @param \Magento\Framework\Data\Form $form
* @return void
*/
protected function _prepareStoreFieldset(\Magento\Framework\Data\Form $form)
{
$websiteModel = $this->_coreRegistry->registry('store_data');
$postData = $this->_coreRegistry->registry('store_post_data');
if ($postData) {
$websiteModel->setData($postData['website']);
}
$fieldset = $form->addFieldset('website_fieldset', array('legend' => __('Web Site Information')));
/* @var $fieldset \Magento\Framework\Data\Form */
$fieldset->addField('website_name', 'text', array('name' => 'website[name]', 'label' => __('Name'), 'value' => $websiteModel->getName(), 'required' => true, 'disabled' => $websiteModel->isReadOnly()));
$fieldset->addField('website_code', 'text', array('name' => 'website[code]', 'label' => __('Code'), 'value' => $websiteModel->getCode(), 'required' => true, 'disabled' => $websiteModel->isReadOnly()));
$fieldset->addField('website_sort_order', 'text', array('name' => 'website[sort_order]', 'label' => __('Sort Order'), 'value' => $websiteModel->getSortOrder(), 'required' => false, 'disabled' => $websiteModel->isReadOnly()));
if ($this->_coreRegistry->registry('store_action') == 'edit') {
$groups = $this->_groupFactory->create()->getCollection()->addWebsiteFilter($websiteModel->getId())->setWithoutStoreViewFilter()->toOptionArray();
$fieldset->addField('website_default_group_id', 'select', array('name' => 'website[default_group_id]', 'label' => __('Default Store'), 'value' => $websiteModel->getDefaultGroupId(), 'values' => $groups, 'required' => false, 'disabled' => $websiteModel->isReadOnly()));
}
if (!$websiteModel->getIsDefault() && $websiteModel->getStoresCount()) {
$fieldset->addField('is_default', 'checkbox', array('name' => 'website[is_default]', 'label' => __('Set as Default'), 'value' => 1, 'disabled' => $websiteModel->isReadOnly()));
} else {
$fieldset->addField('is_default', 'hidden', array('name' => 'website[is_default]', 'value' => $websiteModel->getIsDefault()));
}
$fieldset->addField('website_website_id', 'hidden', array('name' => 'website[website_id]', 'value' => $websiteModel->getId()));
}
开发者ID:aiesh,项目名称:magento2,代码行数:29,代码来源:Website.php
示例20: _formPostInit
/**
* Form post init
*
* @param \Magento\Framework\Data\Form $form
* @return \Magento\Backend\Block\Urlrewrite\Catalog\Edit\Form
*/
protected function _formPostInit($form)
{
// Set form action
$form->setAction($this->_adminhtmlData->getUrl('adminhtml/*/save', array('id' => $this->_getModel()->getId(), 'product' => $this->_getProduct()->getId(), 'category' => $this->_getCategory()->getId())));
// Fill id path, request path and target path elements
/** @var $idPath \Magento\Framework\Data\Form\Element\AbstractElement */
$idPath = $this->getForm()->getElement('id_path');
/** @var $requestPath \Magento\Framework\Data\Form\Element\AbstractElement */
$requestPath = $this->getForm()->getElement('request_path');
/** @var $targetPath \Magento\Framework\Data\Form\Element\AbstractElement */
$targetPath = $this->getForm()->getElement('target_path');
$model = $this->_getModel();
$disablePaths = false;
if (!$model->getId()) {
$product = null;
$category = null;
if ($this->_getProduct()->getId()) {
$product = $this->_getProduct();
$category = $this->_getCategory();
} elseif ($this->_getCategory()->getId()) {
$category = $this->_getCategory();
}
if ($product || $category) {
$idPath->setValue($this->_catalogUrl->generatePath('id', $product, $category));
$sessionData = $this->_getSessionData();
if (!isset($sessionData['request_path'])) {
$requestPath->setValue($this->_catalogUrl->generatePath('request', $product, $category, ''));
}
$targetPath->setValue($this->_catalogUrl->generatePath('target', $product, $category));
$disablePaths = true;
}
} else {
$disablePaths = $model->getProductId() || $model->getCategoryId();
}
// Disable id_path and target_path elements
if ($disablePaths) {
$idPath->setData('disabled', true);
$targetPath->setData('disabled', true);
}
return $this;
}
开发者ID:aiesh,项目名称:magento2,代码行数:47,代码来源:Form.php
注:本文中的Magento\Framework\Data\Form类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论