class BanDelete

Provides a form to unban IP addresses.

Hierarchy

Expanded class hierarchy of BanDelete

1 string reference to 'BanDelete'
ban.routing.yml in drupal/core/modules/ban/ban.routing.yml
drupal/core/modules/ban/ban.routing.yml

File

drupal/core/modules/ban/lib/Drupal/ban/Form/BanDelete.php, line 19
Contains \Drupal\ban\Form\BanDelete.

Namespace

Drupal\ban\Form
View source
class BanDelete extends ConfirmFormBase implements ControllerInterface {

  /**
   * The banned IP address.
   *
   * @var string
   */
  protected $banIp;

  /**
   * Constructs a new BanDelete object.
   *
   * @param \Drupal\ban\BanIpManager $ip_manager
   */
  public function __construct(BanIpManager $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}
   */
  protected function getQuestion() {
    return t('Are you sure you want to unblock %ip?', array(
      '%ip' => $this->banIp,
    ));
  }

  /**
   * {@inheritdoc}
   */
  protected function getConfirmText() {
    return t('Delete');
  }

  /**
   * {@inheritdoc}
   */
  protected function getCancelPath() {
    return 'admin/config/people/ban';
  }

  /**
   * {@inheritdoc}
   *
   * @param string $ban_id
   *   The IP address record ID to unban.
   */
  public function buildForm(array $form, array &$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, array &$form_state) {
    $this->ipManager
      ->unbanIp($this->banIp);
    watchdog('user', 'Deleted %ip', array(
      '%ip' => $this->banIp,
    ));
    drupal_set_message(t('The IP address %ip was deleted.', array(
      '%ip' => $this->banIp,
    )));
    $form_state['redirect'] = 'admin/config/people/ban';
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BanDelete::$banIp protected property The banned IP address.
BanDelete::buildForm public function Overrides ConfirmFormBase::buildForm
BanDelete::create public static function Instantiates a new instance of this controller. Overrides ControllerInterface::create
BanDelete::getCancelPath protected function Returns the page to go to if the user cancels the action. Overrides ConfirmFormBase::getCancelPath
BanDelete::getConfirmText protected function Returns a caption for the button that confirms the action. Overrides ConfirmFormBase::getConfirmText
BanDelete::getFormID public function Returns a unique string identifying the form. Overrides FormInterface::getFormID
BanDelete::getQuestion protected function Returns the question to ask the user. Overrides ConfirmFormBase::getQuestion
BanDelete::submitForm public function Form submission handler. Overrides FormInterface::submitForm
BanDelete::__construct public function Constructs a new BanDelete object.
ConfirmFormBase::getCancelText protected function Returns a caption for the link which cancels the action. 2
ConfirmFormBase::getDescription protected function Returns additional text to display as a description. 10
ConfirmFormBase::getFormName protected function Returns the internal name used to refer to the confirmation item.
ConfirmFormBase::validateForm public function Implements \Drupal\Core\Form\FormInterface::validateForm(). Overrides FormInterface::validateForm 1