class BanAdmin extends FormBase (View source)

internal  
 

Displays banned IP addresses.

Traits

Provides dependency injection friendly methods for serialization.

LinkGeneratorTrait deprecated

Wrapper methods for the Link Generator.

Wrapper methods for the logger factory service.

Provides a trait for the messenger service.

Wrapper methods for the Redirect Destination.

Wrapper methods for \Drupal\Core\StringTranslation\TranslationInterface.

UrlGeneratorTrait deprecated

Wrapper methods for the Url Generator.

Properties

protected array $_serviceIds

An array of service IDs keyed by property name used for serialization.

from  DependencySerializationTrait
protected array $_entityStorages

An array of entity type IDs keyed by the property name of their storages.

from  DependencySerializationTrait
protected LinkGeneratorInterface $linkGenerator

The link generator.

from  LinkGeneratorTrait
protected LoggerChannelFactoryInterface $loggerFactory

The logger channel factory service.

from  LoggerChannelTrait
protected MessengerInterface $messenger

The messenger.

from  MessengerTrait
protected RedirectDestinationInterface $redirectDestination

The redirect destination service.

from  RedirectDestinationTrait
protected TranslationInterface $stringTranslation

The string translation service.

from  StringTranslationTrait
protected UrlGeneratorInterface $urlGenerator

The url generator.

from  UrlGeneratorTrait
protected RequestStack $requestStack

The request stack.

from  FormBase
protected ConfigFactoryInterface $configFactory

The config factory.

from  FormBase
protected RouteMatchInterface $routeMatch

The route match.

from  FormBase
protected BanIpManagerInterface $ipManager

Methods

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

l($text, Url $url) deprecated

Renders a link to a route given a route name and its parameters.

getLinkGenerator() deprecated

Returns the link generator.

$this
setLinkGenerator(LinkGeneratorInterface $generator) deprecated

Sets the link generator service.

LoggerInterface
getLogger(string $channel)

Gets the logger for a specific channel.

$this
setLoggerFactory(LoggerChannelFactoryInterface $logger_factory)

Injects the logger channel factory.

setMessenger(MessengerInterface $messenger)

Sets the messenger.

messenger()

Gets the messenger.

array
getDestinationArray()

Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.

getRedirectDestination()

Returns the redirect destination service.

$this
setRedirectDestination(RedirectDestinationInterface $redirect_destination)

Sets the redirect destination service.

t(string $string, array $args = [], array $options = [])

Translates a string to the current language or to a given language.

formatPlural($count, $singular, $plural, array $args = [], array $options = [])

Formats a string containing a count of items.

getNumberOfPlurals($langcode = NULL)

Returns the number of plurals supported by a given language.

getStringTranslation()

Gets the string translation service.

$this
setStringTranslation(TranslationInterface $translation)

Sets the string translation service to use.

string
url($route_name, $route_parameters = [], $options = []) deprecated

Generates a URL or path for a specific route based on the given parameters.

RedirectResponse
redirect(string $route_name, array $route_parameters = [], array $options = [], int $status = 302) deprecated

Returns a redirect response object for the specified route.

getUrlGenerator() deprecated

Returns the URL generator service.

$this
setUrlGenerator(UrlGeneratorInterface $generator) deprecated

Sets the URL generator service.

static 
create(ContainerInterface $container)

Instantiates a new instance of this class.

validateForm(array $form, FormStateInterface $form_state)

Form validation handler.

config(string $name)

Retrieves a configuration object.

from  FormBase
configFactory()

Gets the config factory for this form.

from  FormBase
$this
setConfigFactory(ConfigFactoryInterface $config_factory)

Sets the config factory for this form.

from  FormBase
resetConfigFactory()

Resets the configuration factory.

from  FormBase
Request
getRequest()

Gets the request object.

from  FormBase
getRouteMatch()

Gets the route match.

from  FormBase
$this
setRequestStack(RequestStack $request_stack)

Sets the request stack object to use.

from  FormBase
currentUser()

Gets the current user.

from  FormBase
LoggerInterface
logger(string $channel)

Gets the logger for a specific channel.

from  FormBase
__construct(BanIpManagerInterface $ip_manager)

Constructs a new BanAdmin object.

string
getFormId()

Returns a unique string identifying the form.

array
buildForm(array $form, FormStateInterface $form_state, string $default_ip = '')

Form constructor.

submitForm(array $form, FormStateInterface $form_state)

Form submission handler.

Details

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

protected GeneratedLink l($text, Url $url) deprecated

deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Link::fromTextAndUrl() instead.

Renders a link to a route given a route name and its parameters.

For details on the arguments, usage, and possible exceptions see \Drupal\Core\Utility\LinkGeneratorInterface::generate().

Parameters

$text
Url $url

Return Value

GeneratedLink

A GeneratedLink object containing a link to the given route and parameters and bubbleable metadata.

See also

https://www.drupal.org/node/2614344
LinkGeneratorInterface::generate

protected LinkGeneratorInterface getLinkGenerator() deprecated

deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Inject the 'link_generator' service or use \Drupal\Core\Link instead

Returns the link generator.

Return Value

LinkGeneratorInterface

The link generator

See also

https://www.drupal.org/node/2614344

$this setLinkGenerator(LinkGeneratorInterface $generator) deprecated

deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Inject the 'link_generator' service or use \Drupal\Core\Link instead

Sets the link generator service.

Parameters

LinkGeneratorInterface $generator

The link generator service.

Return Value

$this

See also

https://www.drupal.org/node/2614344

protected LoggerInterface getLogger(string $channel)

Gets the logger for a specific channel.

Require the use of injected services: https://www.drupal.org/node/2733703

Parameters

string $channel

The name of the channel. Can be any string, but the general practice is to use the name of the subsystem calling this.

Return Value

LoggerInterface

The logger for the given channel.

$this setLoggerFactory(LoggerChannelFactoryInterface $logger_factory)

Injects the logger channel factory.

Parameters

LoggerChannelFactoryInterface $logger_factory

The logger channel factory service.

Return Value

$this

setMessenger(MessengerInterface $messenger)

Sets the messenger.

Parameters

MessengerInterface $messenger

The messenger.

MessengerInterface messenger()

Gets the messenger.

Return Value

MessengerInterface

The messenger.

protected array getDestinationArray()

Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.

Return Value

array

An associative array containing the key:

  • destination: The value of the current request's 'destination' query parameter, if present. This can be either a relative or absolute URL. However, for security, redirection to external URLs is not performed. If the query parameter isn't present, then the URL of the current request is returned.

See also

RedirectDestinationInterface::getAsArray

protected RedirectDestinationInterface getRedirectDestination()

Returns the redirect destination service.

Return Value

RedirectDestinationInterface

The redirect destination helper.

$this setRedirectDestination(RedirectDestinationInterface $redirect_destination)

Sets the redirect destination service.

Parameters

RedirectDestinationInterface $redirect_destination

The redirect destination service.

Return Value

$this

protected TranslatableMarkup t(string $string, array $args = [], array $options = [])

Translates a string to the current language or to a given language.

See \Drupal\Core\StringTranslation\TranslatableMarkup::__construct() for important security information and usage guidelines.

In order for strings to be localized, make them available in one of the ways supported by the

Parameters

string $string

A string containing the English text to translate.

array $args

(optional) An associative array of replacements to make after translation. Based on the first character of the key, the value is escaped and/or themed. See \Drupal\Component\Render\FormattableMarkup::placeholderFormat() for details.

array $options

(optional) An associative array of additional options, with the following elements:

  • 'langcode' (defaults to the current language): A language code, to translate to a language other than what is used to display the page.
  • 'context' (defaults to the empty context): The context the source string belongs to. See the @link i18n Internationalization topic @endlink for more information about string contexts.

Return Value

TranslatableMarkup

An object that, when cast to a string, returns the translated string.

See also

FormattableMarkup::placeholderFormat
TranslatableMarkup::__construct

protected formatPlural($count, $singular, $plural, array $args = [], array $options = [])

Formats a string containing a count of items.

Parameters

$count
$singular
$plural
array $args
array $options

See also

TranslationInterface::formatPlural

protected getNumberOfPlurals($langcode = NULL)

Returns the number of plurals supported by a given language.

Parameters

$langcode

See also

PluralFormulaInterface::getNumberOfPlurals

protected TranslationInterface getStringTranslation()

Gets the string translation service.

Return Value

TranslationInterface

The string translation service.

$this setStringTranslation(TranslationInterface $translation)

Sets the string translation service to use.

Parameters

TranslationInterface $translation

The string translation service.

Return Value

$this

protected string url($route_name, $route_parameters = [], $options = []) deprecated

deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Url::fromUri() instead.

Generates a URL or path for a specific route based on the given parameters.

For details on the arguments, usage, and possible exceptions see \Drupal\Core\Routing\UrlGeneratorInterface::generateFromRoute().

Parameters

$route_name
$route_parameters
$options

Return Value

string

The generated URL for the given route.

See also

UrlGeneratorInterface::generateFromRoute

protected RedirectResponse redirect(string $route_name, array $route_parameters = [], array $options = [], int $status = 302) deprecated

deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Use new RedirectResponse(Url::fromRoute()) instead.

Returns a redirect response object for the specified route.

Parameters

string $route_name

The name of the route to which to redirect.

array $route_parameters

(optional) Parameters for the route.

array $options

(optional) An associative array of additional options.

int $status

(optional) The HTTP redirect status code for the redirect. The default is 302 Found.

Return Value

RedirectResponse

A redirect response object that may be returned by the controller.

protected UrlGeneratorInterface getUrlGenerator() deprecated

deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Use the url_generator service instead.

Returns the URL generator service.

Return Value

UrlGeneratorInterface

The URL generator service.

$this setUrlGenerator(UrlGeneratorInterface $generator) deprecated

deprecated in drupal:8.0.0 and is removed from drupal:9.0.0.

Sets the URL generator service.

Parameters

UrlGeneratorInterface $generator

The url generator service.

Return Value

$this

static create(ContainerInterface $container)

Instantiates a new instance of this class.

This is a factory method that returns a new instance of this class. The factory should pass any needed dependencies into the constructor of this class, but not the container itself. Every call to this method must return a new instance of this class; that is, it may not implement a singleton.

Parameters

ContainerInterface $container

The service container this instance should use.

validateForm(array $form, FormStateInterface $form_state)

Form validation handler.

Parameters

array $form

An associative array containing the structure of the form.

FormStateInterface $form_state

The current state of the form.

protected ImmutableConfig config(string $name)

Retrieves a configuration object.

This is the main entry point to the configuration API. Calling

Parameters

string $name

The name of the configuration object to retrieve. The name corresponds to a configuration file. For @code \Drupal::config('book.admin') @endcode, the config object returned will contain the contents of book.admin configuration file.

Return Value

ImmutableConfig

A configuration object.

protected ConfigFactoryInterface configFactory()

Gets the config factory for this form.

When accessing configuration values, use $this->config(). Only use this when the config factory needs to be manipulated directly.

Return Value

ConfigFactoryInterface

$this setConfigFactory(ConfigFactoryInterface $config_factory)

Sets the config factory for this form.

Parameters

ConfigFactoryInterface $config_factory

The config factory.

Return Value

$this

resetConfigFactory()

Resets the configuration factory.

protected Request getRequest()

Gets the request object.

Return Value

Request

The request object.

protected RouteMatchInterface getRouteMatch()

Gets the route match.

Return Value

RouteMatchInterface

$this setRequestStack(RequestStack $request_stack)

Sets the request stack object to use.

Parameters

RequestStack $request_stack

The request stack object.

Return Value

$this

protected AccountInterface currentUser()

Gets the current user.

Return Value

AccountInterface

The current user.

protected LoggerInterface logger(string $channel)

Gets the logger for a specific channel.

This method exists for backward-compatibility between FormBase and LoggerChannelTrait. Use LoggerChannelTrait::getLogger() instead.

Parameters

string $channel

The name of the channel. Can be any string, but the general practice is to use the name of the subsystem calling this.

Return Value

LoggerInterface

The logger for the given channel.

__construct(BanIpManagerInterface $ip_manager)

Constructs a new BanAdmin object.

Parameters

BanIpManagerInterface $ip_manager

string getFormId()

Returns a unique string identifying the form.

The returned ID should be a unique string that can be a valid PHP function name, since it's used in hook implementation names such as hook_form_FORM_ID_alter().

Return Value

string

The unique string identifying the form.

array buildForm(array $form, FormStateInterface $form_state, string $default_ip = '')

Form constructor.

Parameters

array $form

An associative array containing the structure of the form.

FormStateInterface $form_state

The current state of the form.

string $default_ip

(optional) IP address to be passed on to \Drupal::formBuilder()->getForm() for use as the default value of the IP address form field.

Return Value

array

The form structure.

submitForm(array $form, FormStateInterface $form_state)

Form submission handler.

Parameters

array $form

An associative array containing the structure of the form.

FormStateInterface $form_state

The current state of the form.