You are here

public function SimplesitemapEnginesForm::buildForm in Simple XML sitemap 4.x

Same name and namespace in other branches
  1. 8.3 modules/simple_sitemap_engines/src/Form/SimplesitemapEnginesForm.php \Drupal\simple_sitemap_engines\Form\SimplesitemapEnginesForm::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

modules/simple_sitemap_engines/src/Form/SimplesitemapEnginesForm.php, line 78

Class

SimplesitemapEnginesForm
Form for managing search engine submission settings.

Namespace

Drupal\simple_sitemap_engines\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('simple_sitemap_engines.settings');
  $form['#tree'] = TRUE;
  $form['settings'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('General submission settings'),
    '#prefix' => FormHelper::getDonationText(),
  ];
  $form['settings']['enabled'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Submit the sitemap to search engines'),
    '#description' => $this
      ->t('This enables/disables sitemap submitting; don\'t forget to choose variants below.'),
    '#default_value' => $config
      ->get('enabled'),
  ];
  $form['settings']['submission_interval'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Submission interval'),
    '#options' => FormHelper::getCronIntervalOptions(),
    '#default_value' => $config
      ->get('submission_interval'),
    '#states' => [
      'visible' => [
        ':input[name="settings[enabled]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $form['engines'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Sitemap specific settings'),
    '#markup' => '<div class="description">' . $this
      ->t('Choose which sitemaps are to be submitted to which search engines.<br>Sitemaps can be configured <a href="@url">here</a>.', [
      '@url' => $GLOBALS['base_url'] . '/admin/config/search/simplesitemap',
    ]) . '</div>',
  ];
  $engines = SimpleSitemapEngine::loadMultiple();
  foreach ($engines as $engine_id => $engine) {
    $form['engines'][$engine_id] = [
      '#type' => 'details',
      '#title' => $engine
        ->label(),
      '#open' => !empty($engine->sitemap_variants) || count($engines) === 1,
    ];
    $form['engines'][$engine_id]['variants'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Sitemaps'),
      '#options' => array_map(function ($variant) {
        return $this
          ->t($variant
          ->label());
      }, SimpleSitemap::loadMultiple()),
      '#default_value' => $engine->sitemap_variants,
      '#multiple' => TRUE,
    ];
  }
  return parent::buildForm($form, $form_state);
}