当前位置: 首页>>代码示例>>PHP>>正文


PHP Form::getElement方法代码示例

本文整理汇总了PHP中Magento\Framework\Data\Form::getElement方法的典型用法代码示例。如果您正苦于以下问题:PHP Form::getElement方法的具体用法?PHP Form::getElement怎么用?PHP Form::getElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Framework\Data\Form的用法示例。


在下文中一共展示了Form::getElement方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _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

示例2: _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

示例3: 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

示例4: _handleReadOnlyCustomer

 /**
  * Handle Read-Only customer
  *
  * @param \Magento\Framework\Data\Form $form
  * @param int $customerId
  * @param \Magento\Customer\Service\V1\Data\Eav\AttributeMetadata[] $attributes
  * @return void
  */
 protected function _handleReadOnlyCustomer($form, $customerId, $attributes)
 {
     if ($customerId && !$this->_customerAccountService->canModify($customerId)) {
         foreach ($attributes as $attribute) {
             $element = $form->getElement($attribute->getAttributeCode());
             if ($element) {
                 $element->setReadonly(true, true);
             }
         }
     }
 }
开发者ID:Atlis,项目名称:docker-magento2,代码行数:19,代码来源:Account.php

示例5: prepareGroupIdField

 /**
  * Prepare group id field in the fieldset
  *
  * @param \Magento\Framework\Data\Form $form
  * @param \Magento\Store\Model\Store $storeModel
  * @param \Magento\Framework\Data\Form\Element\Fieldset $fieldset
  * @return \Magento\Framework\Data\Form\Element\Fieldset
  */
 private function prepareGroupIdField(\Magento\Framework\Data\Form $form, \Magento\Store\Model\Store $storeModel, \Magento\Framework\Data\Form\Element\Fieldset $fieldset)
 {
     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', ['name' => 'store[group_id]', 'no_span' => true, 'value' => $storeModel->getGroupId()]);
         } else {
             $fieldset->addField('store_original_group_id', 'hidden', ['name' => 'store[original_group_id]', 'no_span' => true, 'value' => $storeModel->getGroupId()]);
         }
     }
     return $fieldset;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:20,代码来源:Store.php

示例6: updateFromSession

 /**
  * Update form elements from session data
  *
  * @param \Magento\Framework\Data\Form $form
  * @param int $customerId
  * @return void
  */
 protected function updateFromSession(\Magento\Framework\Data\Form $form, $customerId)
 {
     $data = $this->_backendSession->getCustomerFormData();
     if (!empty($data)) {
         $dataCustomerId = isset($data['customer']['entity_id']) ? $data['customer']['entity_id'] : null;
         if (isset($data['subscription']) && $dataCustomerId == $customerId) {
             $form->getElement('subscription')->setIsChecked($data['subscription']);
         }
     }
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:17,代码来源:Newsletter.php

示例7: moveOrginalFields

 /**
  * Move original fields to the new fieldset.
  *
  * @param Form $form Form
  *
  * @return FrontPlugin
  */
 private function moveOrginalFields(Form $form)
 {
     $originalFieldset = $form->getElement('front_fieldset');
     $targetFieldset = $form->getElement('elasticsuite_catalog_attribute_fieldset');
     foreach ($this->movedFields as $elementId) {
         $element = $form->getElement($elementId);
         if ($element) {
             $originalFieldset->removeField($elementId);
             $targetFieldset->addElement($element);
         }
     }
     return $this;
 }
开发者ID:smile-sa,项目名称:elasticsuite,代码行数:20,代码来源:FrontPlugin.php

示例8: _handleReadOnlyCustomer

 /**
  * Handle Read-Only customer
  *
  * @param \Magento\Framework\Data\Form $form
  * @param int $customerId
  * @param AttributeMetadataInterface[] $attributes
  * @return void
  */
 protected function _handleReadOnlyCustomer($form, $customerId, $attributes)
 {
     if ($customerId && $this->_accountManagement->isReadonly($customerId)) {
         foreach ($attributes as $attribute) {
             $element = $form->getElement($attribute->getAttributeCode());
             if ($element) {
                 $element->setReadonly(true, true);
             }
         }
     }
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:19,代码来源:Account.php


注:本文中的Magento\Framework\Data\Form::getElement方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。