// Time out in seconds until cancel URL expires; 24 hours = 86400 seconds.
$timeout = 86400;
// Basic validation of arguments.
$account_data =
$this->userData->
get('user',
$user->
id());
if (isset($account_data['cancel_method'
]) && !
empty($timestamp) && !
empty($hashed_pass)) { // Validate expiration and hashed password/login.
if ($user->
id() &&
$this->
validatePathParameters($user,
$timestamp,
$hashed_pass,
$timeout)) { $edit =
[ 'user_cancel_notify' =>
$account_data['cancel_notify'
] ??
$this->
config('user.settings'
)->
get('notify.status_canceled'
),
];
user_cancel($edit,
$user->
id(),
$account_data['cancel_method'
]);
// Since user_cancel() is not invoked via Form API, batch processing
// needs to be invoked manually and should redirect to the front page
// after completion.
return batch_process('<front>'
);
} else { $this->
messenger()->
addError($this->
t('You have tried to use an account cancellation link that has expired. Please request a new one using the form below.'
));
return $this->
redirect('entity.user.cancel_form',
['user' =>
$user->
id()],
['absolute' => TRUE
]);
} } throw new AccessDeniedHttpException();
}