/** * Prepare form for render * * @return void */ protected function _prepareLayout() { parent::_prepareLayout(); /** @var \Magento\Framework\Data\Form $form */ $form = $this->_formFactory->create(); $groupId = $this->_coreRegistry->registry(RegistryConstants::CURRENT_GROUP_ID); /** @var \Magento\Customer\Service\V1\Data\CustomerGroup $customerGroup */ if (is_null($groupId)) { $customerGroup = $this->_groupBuilder->create(); } else { $customerGroup = $this->_groupService->getGroup($groupId); } $fieldset = $form->addFieldset('base_fieldset', array('legend' => __('Group Information'))); $validateClass = sprintf('required-entry validate-length maximum-length-%d', \Magento\Customer\Service\V1\CustomerGroupServiceInterface::GROUP_CODE_MAX_LENGTH); $name = $fieldset->addField('customer_group_code', 'text', array('name' => 'code', 'label' => __('Group Name'), 'title' => __('Group Name'), 'note' => __('Maximum length must be less then %1 symbols', \Magento\Customer\Service\V1\CustomerGroupServiceInterface::GROUP_CODE_MAX_LENGTH), 'class' => $validateClass, 'required' => true)); if ($customerGroup->getId() == 0 && $customerGroup->getCode()) { $name->setDisabled(true); } $fieldset->addField('tax_class_id', 'select', array('name' => 'tax_class', 'label' => __('Tax Class'), 'title' => __('Tax Class'), 'class' => 'required-entry', 'required' => true, 'values' => $this->_taxCustomer->toOptionArray(false))); if (!is_null($customerGroup->getId())) { // If edit add id $form->addField('id', 'hidden', array('name' => 'id', 'value' => $customerGroup->getId())); } if ($this->_backendSession->getCustomerGroupData()) { $form->addValues($this->_backendSession->getCustomerGroupData()); $this->_backendSession->setCustomerGroupData(null); } else { // TODO: need to figure out how the DATA can work with forms $form->addValues(array('id' => $customerGroup->getId(), 'customer_group_code' => $customerGroup->getCode(), 'tax_class_id' => $customerGroup->getTaxClassId())); } $form->setUseContainer(true); $form->setId('edit_form'); $form->setAction($this->getUrl('customer/*/save')); $form->setMethod('post'); $this->setForm($form); }
/** * {@inheritdoc} */ public function getGroup($groupId) { $customerGroup = $this->_groupRegistry->retrieve($groupId); $this->_customerGroupBuilder->setId($customerGroup->getId())->setCode($customerGroup->getCode())->setTaxClassId($customerGroup->getTaxClassId()); return $this->_customerGroupBuilder->create(); }