annotate core/modules/user/src/ProfileForm.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents af1871eacc83
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\user;
Chris@0 4
Chris@0 5 use Drupal\Core\Form\FormStateInterface;
Chris@0 6
Chris@0 7 /**
Chris@0 8 * Form handler for the profile forms.
Chris@14 9 *
Chris@14 10 * @internal
Chris@0 11 */
Chris@0 12 class ProfileForm extends AccountForm {
Chris@0 13
Chris@0 14 /**
Chris@0 15 * {@inheritdoc}
Chris@0 16 */
Chris@0 17 protected function actions(array $form, FormStateInterface $form_state) {
Chris@0 18 $element = parent::actions($form, $form_state);
Chris@0 19
Chris@0 20 // The user account being edited.
Chris@0 21 $account = $this->entity;
Chris@0 22
Chris@0 23 $element['delete']['#type'] = 'submit';
Chris@0 24 $element['delete']['#value'] = $this->t('Cancel account');
Chris@0 25 $element['delete']['#submit'] = ['::editCancelSubmit'];
Chris@18 26 $element['delete']['#access'] = $account->id() > 1 && $account->access('delete');
Chris@0 27
Chris@0 28 return $element;
Chris@0 29 }
Chris@0 30
Chris@0 31 /**
Chris@0 32 * {@inheritdoc}
Chris@0 33 */
Chris@0 34 public function save(array $form, FormStateInterface $form_state) {
Chris@0 35 $account = $this->entity;
Chris@0 36 $account->save();
Chris@0 37 $form_state->setValue('uid', $account->id());
Chris@0 38
Chris@17 39 $this->messenger()->addStatus($this->t('The changes have been saved.'));
Chris@0 40 }
Chris@0 41
Chris@0 42 /**
Chris@0 43 * Provides a submit handler for the 'Cancel account' button.
Chris@0 44 */
Chris@0 45 public function editCancelSubmit($form, FormStateInterface $form_state) {
Chris@0 46 $destination = [];
Chris@0 47 $query = $this->getRequest()->query;
Chris@0 48 if ($query->has('destination')) {
Chris@0 49 $destination = ['destination' => $query->get('destination')];
Chris@0 50 $query->remove('destination');
Chris@0 51 }
Chris@0 52 // We redirect from user/%/edit to user/%/cancel to make the tabs disappear.
Chris@0 53 $form_state->setRedirect(
Chris@0 54 'entity.user.cancel_form',
Chris@0 55 ['user' => $this->entity->id()],
Chris@0 56 ['query' => $destination]
Chris@0 57 );
Chris@0 58 }
Chris@0 59
Chris@0 60 }