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