You are here

public function W3CValidatorOperationForm::buildForm in W3C Validator 8

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides FormInterface::buildForm

File

src/Form/W3CValidatorOperationForm.php, line 65

Class

W3CValidatorOperationForm
Provides the operation form on report page.

Namespace

Drupal\w3c_validator\Form

Code

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;
}