You are here

public function XmlSitemapEnginesSettingsForm::buildForm in XML sitemap 8

Same name and namespace in other branches
  1. 2.x xmlsitemap_engines/src/Form/XmlSitemapEnginesSettingsForm.php \Drupal\xmlsitemap_engines\Form\XmlSitemapEnginesSettingsForm::buildForm()

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

xmlsitemap_engines/src/Form/XmlSitemapEnginesSettingsForm.php, line 80

Class

XmlSitemapEnginesSettingsForm
Configure xmlsitemap engines settings for this site.

Namespace

Drupal\xmlsitemap_engines\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {

  // Build the list of support engines for the checkboxes options.
  $engines = xmlsitemap_engines_get_engine_info();
  $engine_options = [];
  foreach ($engines as $engine => $engine_info) {
    $engine_options[$engine] = $engine_info['name'];
  }
  asort($engine_options);
  $form['engines'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Submit the sitemap to the following engines'),
    '#default_value' => $this
      ->config('xmlsitemap_engines.settings')
      ->get('engines'),
    '#options' => $engine_options,
  ];
  $lifetimes = [
    3600,
    10800,
    21600,
    32400,
    43200,
    86400,
    172800,
    259200,
    604800,
    604800 * 2,
    604800 * 4,
  ];
  $lifetimes = array_combine($lifetimes, $lifetimes);
  $format_lifetimes = [];
  foreach ($lifetimes as $value) {
    $format_lifetimes[$value] = $this->date
      ->formatInterval($value);
  }
  $form['minimum_lifetime'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Do not submit more often than every'),
    '#options' => $format_lifetimes,
    '#default_value' => $this
      ->config('xmlsitemap_engines.settings')
      ->get('minimum_lifetime'),
  ];
  $form['xmlsitemap_engines_submit_updated'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Only submit if the sitemap has been updated since the last submission.'),
    '#default_value' => $this->state
      ->get('xmlsitemap_engines_submit_updated'),
  ];
  $form['custom_urls'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Custom submission URLs'),
    '#description' => $this
      ->t('Enter one URL per line. The token [sitemap] will be replaced with the URL to your sitemap. For example: %example-before would become %example-after.', [
      '%example-before' => 'http://example.com/ping?[sitemap]',
      '%example-after' => xmlsitemap_engines_prepare_url('http://example.com/ping?[sitemap]', Url::fromRoute('xmlsitemap.sitemap_xml', [], [
        'absolute' => TRUE,
      ])
        ->toString()),
    ]),
    '#default_value' => $this
      ->config('xmlsitemap_engines.settings')
      ->get('custom_urls'),
    '#rows' => 2,
    '#wysiwyg' => FALSE,
  ];

  // Ensure the xmlsitemap_engines variable gets filtered to a simple array.
  $form['array_filter'] = [
    '#type' => 'value',
    '#value' => TRUE,
  ];
  return parent::buildForm($form, $form_state);
}