/** * {@inheritdoc} */ protected function _prepareForm() { $userId = $this->_authSession->getUser()->getId(); $user = $this->_userFactory->create()->load($userId); $user->unsetData('password'); /** @var \Magento\Framework\Data\Form $form */ $form = $this->_formFactory->create(); $fieldset = $form->addFieldset('base_fieldset', ['legend' => __('Account Information')]); $fieldset->addField('username', 'text', ['name' => 'username', 'label' => __('User Name'), 'title' => __('User Name'), 'required' => true]); $fieldset->addField('firstname', 'text', ['name' => 'firstname', 'label' => __('First Name'), 'title' => __('First Name'), 'required' => true]); $fieldset->addField('lastname', 'text', ['name' => 'lastname', 'label' => __('Last Name'), 'title' => __('Last Name'), 'required' => true]); $fieldset->addField('user_id', 'hidden', ['name' => 'user_id']); $fieldset->addField('email', 'text', ['name' => 'email', 'label' => __('Email'), 'title' => __('User Email'), 'required' => true]); $fieldset->addField('password', 'password', ['name' => 'password', 'label' => __('New Password'), 'title' => __('New Password'), 'class' => 'input-text validate-admin-password']); $fieldset->addField('confirmation', 'password', ['name' => 'password_confirmation', 'label' => __('Password Confirmation'), 'class' => 'input-text validate-cpassword']); $fieldset->addField('interface_locale', 'select', ['name' => 'interface_locale', 'label' => __('Interface Locale'), 'title' => __('Interface Locale'), 'values' => $this->_localeLists->getTranslatedOptionLocales(), 'class' => 'select']); $verificationFieldset = $form->addFieldset('current_user_verification_fieldset', ['legend' => __('Current User Identity Verification')]); $verificationFieldset->addField(self::IDENTITY_VERIFICATION_PASSWORD_FIELD, 'password', ['name' => self::IDENTITY_VERIFICATION_PASSWORD_FIELD, 'label' => __('Your Password'), 'id' => self::IDENTITY_VERIFICATION_PASSWORD_FIELD, 'title' => __('Your Password'), 'class' => 'input-text validate-current-password required-entry', 'required' => true]); $data = $user->getData(); unset($data[self::IDENTITY_VERIFICATION_PASSWORD_FIELD]); $form->setValues($data); $form->setAction($this->getUrl('adminhtml/system_account/save')); $form->setMethod('post'); $form->setUseContainer(true); $form->setId('edit_form'); $this->setForm($form); return parent::_prepareForm(); }
/** * Prepare form fields * * @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @return \Magento\Backend\Block\Widget\Form */ protected function _prepareForm() { /** @var $model \Magento\User\Model\User */ $model = $this->_coreRegistry->registry('permissions_user'); /** @var \Magento\Framework\Data\Form $form */ $form = $this->_formFactory->create(); $form->setHtmlIdPrefix('user_'); $baseFieldset = $form->addFieldset('base_fieldset', ['legend' => __('Account Information')]); if ($model->getUserId()) { $baseFieldset->addField('user_id', 'hidden', ['name' => 'user_id']); } else { if (!$model->hasData('is_active')) { $model->setIsActive(1); } } $baseFieldset->addField('username', 'text', ['name' => 'username', 'label' => __('User Name'), 'id' => 'username', 'title' => __('User Name'), 'required' => true]); $baseFieldset->addField('firstname', 'text', ['name' => 'firstname', 'label' => __('First Name'), 'id' => 'firstname', 'title' => __('First Name'), 'required' => true]); $baseFieldset->addField('lastname', 'text', ['name' => 'lastname', 'label' => __('Last Name'), 'id' => 'lastname', 'title' => __('Last Name'), 'required' => true]); $baseFieldset->addField('email', 'text', ['name' => 'email', 'label' => __('Email'), 'id' => 'customer_email', 'title' => __('User Email'), 'class' => 'required-entry validate-email', 'required' => true]); $isNewObject = $model->isObjectNew(); if ($isNewObject) { $passwordLabel = __('Password'); } else { $passwordLabel = __('New Password'); } $confirmationLabel = __('Password Confirmation'); $this->_addPasswordFields($baseFieldset, $passwordLabel, $confirmationLabel, $isNewObject); $baseFieldset->addField('interface_locale', 'select', ['name' => 'interface_locale', 'label' => __('Interface Locale'), 'title' => __('Interface Locale'), 'values' => $this->_LocaleLists->getTranslatedOptionLocales(), 'class' => 'select']); if ($this->_authSession->getUser()->getId() != $model->getUserId()) { $baseFieldset->addField('is_active', 'select', ['name' => 'is_active', 'label' => __('This account is'), 'id' => 'is_active', 'title' => __('Account Status'), 'class' => 'input-select', 'options' => ['1' => __('Active'), '0' => __('Inactive')]]); } $baseFieldset->addField('user_roles', 'hidden', ['name' => 'user_roles', 'id' => '_user_roles']); $currentUserVerificationFieldset = $form->addFieldset('current_user_verification_fieldset', ['legend' => __('Current User Identity Verification')]); $currentUserVerificationFieldset->addField(self::CURRENT_USER_PASSWORD_FIELD, 'password', ['name' => self::CURRENT_USER_PASSWORD_FIELD, 'label' => __('Your Password'), 'id' => self::CURRENT_USER_PASSWORD_FIELD, 'title' => __('Your Password'), 'class' => 'input-text validate-current-password required-entry', 'required' => true]); $data = $model->getData(); unset($data['password']); unset($data[self::CURRENT_USER_PASSWORD_FIELD]); $form->setValues($data); $this->setForm($form); return parent::_prepareForm(); }
/** * Retrieve locale select element * * @return string */ public function getLocaleSelect() { $html = $this->getLayout()->createBlock('Magento\\Framework\\View\\Element\\Html\\Select')->setName('locale')->setId('interface_locale')->setTitle(__('Interface Language'))->setClass('select locale-switcher-select')->setValue($this->_localeResolver->getLocale()->__toString())->setOptions($this->_localeLists->getTranslatedOptionLocales())->getHtml(); return $html; }
/** * Retrieve locale dropdown HTML * * @return string */ public function getLocaleSelect() { $html = $this->getLayout()->createBlock('Magento\\Framework\\View\\Element\\Html\\Select')->setName('config[locale]')->setId('locale')->setTitle(__('Locale'))->setClass('required-entry')->setValue($this->getLocale()->__toString())->setOptions($this->_localeLists->getTranslatedOptionLocales())->getHtml(); return $html; }