3 namespace Drupal\ban\Form;
5 use Drupal\Core\Form\ConfirmFormBase;
6 use Drupal\ban\BanIpManagerInterface;
7 use Drupal\Core\Form\FormStateInterface;
9 use Symfony\Component\DependencyInjection\ContainerInterface;
10 use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
13 * Provides a form to unban IP addresses.
15 class BanDelete extends ConfirmFormBase {
18 * The banned IP address.
27 * @var \Drupal\ban\BanIpManagerInterface
32 * Constructs a new BanDelete object.
34 * @param \Drupal\ban\BanIpManagerInterface $ip_manager
37 public function __construct(BanIpManagerInterface $ip_manager) {
38 $this->ipManager = $ip_manager;
44 public static function create(ContainerInterface $container) {
46 $container->get('ban.ip_manager')
53 public function getFormId() {
54 return 'ban_ip_delete_form';
60 public function getQuestion() {
61 return $this->t('Are you sure you want to unblock %ip?', ['%ip' => $this->banIp]);
67 public function getConfirmText() {
68 return $this->t('Delete');
74 public function getCancelUrl() {
75 return new Url('ban.admin_page');
81 * @param string $ban_id
82 * The IP address record ID to unban.
84 public function buildForm(array $form, FormStateInterface $form_state, $ban_id = '') {
85 if (!$this->banIp = $this->ipManager->findById($ban_id)) {
86 throw new NotFoundHttpException();
88 return parent::buildForm($form, $form_state);
94 public function submitForm(array &$form, FormStateInterface $form_state) {
95 $this->ipManager->unbanIp($this->banIp);
96 $this->logger('user')->notice('Deleted %ip', ['%ip' => $this->banIp]);
97 drupal_set_message($this->t('The IP address %ip was deleted.', ['%ip' => $this->banIp]));
98 $form_state->setRedirectUrl($this->getCancelUrl());