Patched to Drupal 8.4.8 level. See https://www.drupal.org/sa-core-2018-004 and patch...
[yaffs-website] / web / core / modules / user / src / ProfileForm.php
1 <?php
2
3 namespace Drupal\user;
4
5 use Drupal\Core\Form\FormStateInterface;
6
7 /**
8  * Form handler for the profile forms.
9  */
10 class ProfileForm extends AccountForm {
11
12   /**
13    * {@inheritdoc}
14    */
15   protected function actions(array $form, FormStateInterface $form_state) {
16     $element = parent::actions($form, $form_state);
17
18     // The user account being edited.
19     $account = $this->entity;
20
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'));
27
28     return $element;
29   }
30
31   /**
32    * {@inheritdoc}
33    */
34   public function save(array $form, FormStateInterface $form_state) {
35     $account = $this->entity;
36     $account->save();
37     $form_state->setValue('uid', $account->id());
38
39     drupal_set_message($this->t('The changes have been saved.'));
40   }
41
42   /**
43    * Provides a submit handler for the 'Cancel account' button.
44    */
45   public function editCancelSubmit($form, FormStateInterface $form_state) {
46     $destination = [];
47     $query = $this->getRequest()->query;
48     if ($query->has('destination')) {
49       $destination = ['destination' => $query->get('destination')];
50       $query->remove('destination');
51     }
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]
57     );
58   }
59
60 }