You are here

public function ResourceHintsConfigForm::buildForm in Resource Hints 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 ConfigFormBase::buildForm

File

src/Form/ResourceHintsConfigForm.php, line 37

Class

ResourceHintsConfigForm
Configure resource hints for this site.

Namespace

Drupal\resource_hints\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('resource_hints.settings');
  $form['dns_prefetch'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('DNS Prefetch'),
    '#open' => TRUE,
  ];
  $form['dns_prefetch']['dns_prefetch_output'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Output type'),
    '#options' => [
      self::OUTPUT_LINK_HEADER => $this
        ->t('Link Header'),
      self::OUTPUT_LINK_ELEMENT => $this
        ->t('Link Element'),
    ],
    '#default_value' => $config
      ->get('dns_prefetch_output'),
    '#description' => $this
      ->t('Resource hints can be output as an HTTP Link header or HTML link element'),
  ];
  $form['dns_prefetch']['dns_prefetch_resources'] = [
    '#type' => 'textarea',
    '#default_value' => implode(PHP_EOL, $config
      ->get('dns_prefetch_resources')),
    '#title' => $this
      ->t('Resources'),
    '#description' => $this
      ->t('The DNS resources you wish to be prefetched. Enter one resource per line.'),
  ];
  $form['dns_prefetch']['dns_prefetch_control'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('DNS Prefetch Control'),
    '#options' => [
      self::DNS_PREFETCH_ENABLED => $this
        ->t('Enabled'),
      self::DNS_PREFETCH_DISABLED => $this
        ->t('Disabled'),
    ],
    '#default_value' => $config
      ->get('dns_prefetch_control'),
    '#description' => $this
      ->t('By default browsers will not use DNS prefetching when a page is served via HTTPS, you must explicitly enable prefetching for HTTPS. Disabling prefetching will prevent browsers using prefetching and any inline attempts to enable it will be ignored.'),
  ];
  $form['preconnect'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Preconnect'),
    '#open' => TRUE,
  ];
  $form['preconnect']['preconnect_output'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Output type'),
    '#options' => [
      self::OUTPUT_LINK_HEADER => $this
        ->t('Link Header'),
      self::OUTPUT_LINK_ELEMENT => $this
        ->t('Link Element'),
    ],
    '#default_value' => $config
      ->get('preconnect_output'),
    '#description' => $this
      ->t('Resource hints can be output as an HTTP Link header or HTML link element'),
  ];
  $form['preconnect']['preconnect_resources'] = [
    '#type' => 'textarea',
    '#default_value' => implode(PHP_EOL, $config
      ->get('preconnect_resources')),
    '#title' => $this
      ->t('Resources'),
    '#description' => $this
      ->t('The resources you wish to be preconnected. Enter one resource per line.'),
  ];
  $form['prefetch'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Prefetch'),
    '#open' => TRUE,
  ];
  $form['prefetch']['prefetch_output'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Output type'),
    '#options' => [
      self::OUTPUT_LINK_HEADER => $this
        ->t('Link Header'),
      self::OUTPUT_LINK_ELEMENT => $this
        ->t('Link Element'),
    ],
    '#default_value' => $config
      ->get('prefetch_output'),
    '#description' => $this
      ->t('Resource hints can be output as an HTTP Link header or HTML link element'),
  ];
  $form['prefetch']['prefetch_resources'] = [
    '#type' => 'textarea',
    '#default_value' => implode(PHP_EOL, $config
      ->get('prefetch_resources')),
    '#title' => $this
      ->t('Resources'),
    '#description' => $this
      ->t('The resources you wish to be prefetched. Enter one resource per line.'),
  ];
  $form['prerender'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Prerender'),
    '#open' => TRUE,
  ];
  $form['prerender']['prerender_output'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Output type'),
    '#options' => [
      self::OUTPUT_LINK_HEADER => $this
        ->t('Link Header'),
      self::OUTPUT_LINK_ELEMENT => $this
        ->t('Link Element'),
    ],
    '#default_value' => $config
      ->get('prerender_output'),
    '#description' => $this
      ->t('Resource hints can be output as an HTTP Link header or HTML link element'),
  ];
  $form['prerender']['prerender_resources'] = [
    '#type' => 'textarea',
    '#default_value' => implode(PHP_EOL, $config
      ->get('prerender_resources')),
    '#title' => $this
      ->t('Resources'),
    '#description' => $this
      ->t('The resources you wish to be prerendered. Enter one resource per line.'),
  ];
  return parent::buildForm($form, $form_state);
}