Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 24 |
| BanDelete | |
0.00% |
0 / 1 |
|
0.00% |
0 / 8 |
90 | |
0.00% |
0 / 24 |
| __construct | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| create | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
|||
| getFormId | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| getQuestion | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| getConfirmText | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| getCancelUrl | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| buildForm | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 5 |
|||
| submitForm | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 5 |
|||
| <?php | |
| /** | |
| * @file | |
| * Contains \Drupal\ban\Form\BanDelete. | |
| */ | |
| namespace Drupal\ban\Form; | |
| use Drupal\Core\Form\ConfirmFormBase; | |
| use Drupal\ban\BanIpManagerInterface; | |
| use Drupal\Core\Form\FormStateInterface; | |
| use Drupal\Core\Url; | |
| use Symfony\Component\DependencyInjection\ContainerInterface; | |
| use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | |
| /** | |
| * Provides a form to unban IP addresses. | |
| */ | |
| class BanDelete extends ConfirmFormBase { | |
| /** | |
| * The banned IP address. | |
| * | |
| * @var string | |
| */ | |
| protected $banIp; | |
| /** | |
| * Constructs a new BanDelete object. | |
| * | |
| * @param \Drupal\ban\BanIpManagerInterface $ip_manager | |
| * The IP manager. | |
| */ | |
| public function __construct(BanIpManagerInterface $ip_manager) { | |
| $this->ipManager = $ip_manager; | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public static function create(ContainerInterface $container) { | |
| return new static( | |
| $container->get('ban.ip_manager') | |
| ); | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function getFormId() { | |
| return 'ban_ip_delete_form'; | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function getQuestion() { | |
| return $this->t('Are you sure you want to unblock %ip?', array('%ip' => $this->banIp)); | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function getConfirmText() { | |
| return $this->t('Delete'); | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function getCancelUrl() { | |
| return new Url('ban.admin_page'); | |
| } | |
| /** | |
| * {@inheritdoc} | |
| * | |
| * @param string $ban_id | |
| * The IP address record ID to unban. | |
| */ | |
| public function buildForm(array $form, FormStateInterface $form_state, $ban_id = '') { | |
| if (!$this->banIp = $this->ipManager->findById($ban_id)) { | |
| throw new NotFoundHttpException(); | |
| } | |
| return parent::buildForm($form, $form_state); | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function submitForm(array &$form, FormStateInterface $form_state) { | |
| $this->ipManager->unbanIp($this->banIp); | |
| $this->logger('user')->notice('Deleted %ip', array('%ip' => $this->banIp)); | |
| drupal_set_message($this->t('The IP address %ip was deleted.', array('%ip' => $this->banIp))); | |
| $form_state->setRedirectUrl($this->getCancelUrl()); | |
| } | |
| } |