SubscriptionCancelForm.php in Mailing List 8
File
src/Form/SubscriptionCancelForm.php
View source
<?php
namespace Drupal\mailing_list\Form;
use Drupal\Core\Entity\ContentEntityDeleteForm;
use Drupal\Core\Url;
class SubscriptionCancelForm extends ContentEntityDeleteForm {
protected function getRedirectUrl() {
return $this
->getCancelUrl();
}
public function getCancelUrl() {
$url = parent::getCancelUrl();
if (!$url
->access() && $this->entity) {
$url = $this->entity
->toUrl();
}
if (!$url
->access()) {
$url = Url::fromRoute('view.mailing_list_subscriptions.page_user_subscriptions_tab', [
'user' => $this
->currentUser()
->id(),
]);
}
if (!$url
->access()) {
$url = Url::fromRoute('<front>');
}
return $url;
}
public function getQuestion() {
$subscription = $this
->getEntity();
$t_args = [
'%label' => $subscription
->label(),
'%list' => $subscription
->getList()
->label(),
];
return $this
->currentUser()
->id() == $subscription
->getOwnerId() ? $this
->t('Are you sure you want to cancel your subscription %label to the %list mailing list?', $t_args) : $this
->t('Are you sure you want to cancel the subscription %label to the %list mailing list?', $t_args);
}
protected function getDeletionMessage() {
$subscription = $this
->getEntity();
$list = $subscription
->getList();
$message = $list
->getOnCancellationMessage();
return $message ?: $this
->t('Your subscription %label to the %list mailing list has been cancelled.', [
'%label' => $subscription
->label(),
'%list' => $list
->label(),
]);
}
public function getConfirmText() {
return $this
->t('Yes');
}
public function getCancelText() {
return $this
->t('No');
}
}