示例#1
0
 /**
  * {@inheritdoc}
  */
 protected function actions(array $form, FormStateInterface $form_state)
 {
     $element = parent::actions($form, $form_state);
     // The user account being edited.
     $account = $this->entity;
     // The user doing the editing.
     $user = $this->currentUser();
     $element['delete']['#type'] = 'submit';
     $element['delete']['#value'] = $this->t('Cancel account');
     $element['delete']['#submit'] = array('::editCancelSubmit');
     $element['delete']['#access'] = $account->id() > 1 && ($account->id() == $user->id() && $user->hasPermission('cancel account') || $user->hasPermission('administer users'));
     return $element;
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $admin = $form_state->getValue('administer_users');
     if (!\Drupal::config('user.settings')->get('verify_mail') || $admin) {
         $pass = $form_state->getValue('pass');
     } else {
         $pass = user_password();
     }
     // Remove unneeded values.
     $form_state->cleanValues();
     $form_state->setValue('pass', $pass);
     $form_state->setValue('init', $form_state->getValue('mail'));
     parent::submitForm($form, $form_state);
 }
示例#3
0
 /**
  * Overrides Drupal\Core\Entity\EntityForm::submit().
  */
 public function submit(array $form, FormStateInterface $form_state)
 {
     $admin = $form_state['values']['administer_users'];
     if (!\Drupal::config('user.settings')->get('verify_mail') || $admin) {
         $pass = $form_state['values']['pass'];
     } else {
         $pass = user_password();
     }
     // Remove unneeded values.
     form_state_values_clean($form_state);
     $form_state['values']['pass'] = $pass;
     $form_state['values']['init'] = $form_state['values']['mail'];
     parent::submit($form, $form_state);
 }