5 use Drupal\Core\Form\FormStateInterface;
8 * Form handler for the profile forms.
12 class ProfileForm extends AccountForm {
17 protected function actions(array $form, FormStateInterface $form_state) {
18 $element = parent::actions($form, $form_state);
20 // The user account being edited.
21 $account = $this->entity;
23 // The user doing the editing.
24 $user = $this->currentUser();
25 $element['delete']['#type'] = 'submit';
26 $element['delete']['#value'] = $this->t('Cancel account');
27 $element['delete']['#submit'] = ['::editCancelSubmit'];
28 $element['delete']['#access'] = $account->id() > 1 && (($account->id() == $user->id() && $user->hasPermission('cancel account')) || $user->hasPermission('administer users'));
36 public function save(array $form, FormStateInterface $form_state) {
37 $account = $this->entity;
39 $form_state->setValue('uid', $account->id());
41 $this->messenger()->addStatus($this->t('The changes have been saved.'));
45 * Provides a submit handler for the 'Cancel account' button.
47 public function editCancelSubmit($form, FormStateInterface $form_state) {
49 $query = $this->getRequest()->query;
50 if ($query->has('destination')) {
51 $destination = ['destination' => $query->get('destination')];
52 $query->remove('destination');
54 // We redirect from user/%/edit to user/%/cancel to make the tabs disappear.
55 $form_state->setRedirect(
56 'entity.user.cancel_form',
57 ['user' => $this->entity->id()],
58 ['query' => $destination]