class W3CValidatorOperationForm in W3C Validator 8
Provides the operation form on report page.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\w3c_validator\Form\W3CValidatorOperationForm
Expanded class hierarchy of W3CValidatorOperationForm
File
- src/
Form/ W3CValidatorOperationForm.php, line 16
Namespace
Drupal\w3c_validator\FormView source
class W3CValidatorOperationForm extends FormBase {
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $connection;
/**
* The W3C process service.
*
* @var \Drupal\w3c_validator\W3CProcessor
*/
protected $w3cProcessor;
/**
* Constructs a new W3CValidatorOperationForm.
*
* @param \Drupal\Core\Database\Connection $connection
* The database connection.
* @param \Drupal\w3c_validator\W3CProcessor $w3c_processor
* The validation processor.
*/
public function __construct(Connection $connection, W3CProcessor $w3c_processor) {
$this->connection = $connection;
$this->w3cProcessor = $w3c_processor;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('database'), $container
->get('w3c.processor'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'w3c_validator_operation_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$validator_url = $this->w3cProcessor
->getValidatorUrl();
$warning = '';
if ($this
->isRateLimitService($validator_url)) {
$warning = $this
->t('This will revalidate all of the following pages. This operation may be long.');
$warning .= '<br/><br/><i><b>' . $this
->t('BEWARE : You are using the W3C HTML Validator at @path.', [
'@path' => Link::fromTextAndUrl($validator_url, Url::fromUri($validator_url))
->toString(),
]) . '<br/>' . $this
->t('Using an external online service may be consider spam and abuse of service. Therefore, performing this operation, you may get banned temporarily.') . '<br/>' . $this
->t('Configure a local service on @configuration', [
'@configuration' => Link::createFromRoute('W3C validator settings page', 'w3c_validator.settings')
->toString(),
]) . '</b></i>';
}
$form['advanced_operations'] = [
'#type' => 'details',
'#title' => $this
->t('advanced operations'),
'#description' => $warning,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
];
// Load module settings.
$module_settings = $this
->configFactory()
->get('w3c_validator.settings');
// Use admin helper tool option settings.
$form['advanced_operations']['use_token'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Validate as logged-in user.'),
'#description' => $this
->t('If enabled, pages will be validated as you can see it. Otherwise, as an anonymous user.'),
'#default_value' => $module_settings
->get('use_token'),
];
// Include admin pages.
$form['advanced_operations']['admin_pages'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Include admin pages.'),
'#description' => $this
->t('If enabled, admin pages will be included in validation.'),
'#default_value' => $module_settings
->get('admin_pages'),
];
$form['advanced_operations']['w3c_validator_revalidate_all'] = [
'#type' => 'submit',
'#value' => 'Re-validate all pages',
'#prefix' => '<br/>',
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getValues();
// Save global configurations.
$this->configFactory
->getEditable('w3c_validator.settings')
->set('use_token', $values['use_token'])
->set('admin_pages', $values['admin_pages'])
->save();
$form_state
->setRedirect('w3c_validator.confirm');
}
/**
* Checks if service belong to a known rate limited service.
*
* @param string $service
* The service name.
*
* @return bool
* true/false if the service is know to have a rate limit.
*/
protected function isRateLimitService($service) {
$services = [
'validator.nu',
'validator.w3.org',
];
return in_array(parse_url($service, PHP_URL_HOST), $services);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Retrieves a configuration object. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
62 |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. | |
W3CValidatorOperationForm:: |
protected | property | The database connection. | |
W3CValidatorOperationForm:: |
protected | property | The W3C process service. | |
W3CValidatorOperationForm:: |
public | function |
Form constructor. Overrides FormInterface:: |
|
W3CValidatorOperationForm:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
W3CValidatorOperationForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
W3CValidatorOperationForm:: |
protected | function | Checks if service belong to a known rate limited service. | |
W3CValidatorOperationForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
W3CValidatorOperationForm:: |
public | function | Constructs a new W3CValidatorOperationForm. |