SimplesitemapSettingsForm.php 1.31 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
<?php

/**
 * @file
 * Contains \Drupal\xmlsitemap\Form\SimplesitemapSettingsForm.
 */

namespace Drupal\simplesitemap\Form;

use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
12
use Drupal\simplesitemap\Simplesitemap;
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36

/**
 * SimplesitemapSettingsFrom
 */
class SimplesitemapSettingsForm extends ConfigFormBase {

  /**
   * {@inheritdoc}
   */
  public function getFormID() {
    return 'simplesitemap_settings_form';
  }

  /**
   * {@inheritdoc}
   */
  protected function getEditableConfigNames() {
    return ['simplesitemap.settings'];
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
37 38 39

    $form['simplesitemap_settings']['rebuild'] = array(
      '#title' => t('Rebuild sitemap'),
40
      '#type' => 'fieldset',
41
      '#markup' => '<p>' . t('This will rebuild the XML sitemap for all languages.') . '</p>',
42 43
    );

44 45 46 47 48 49 50 51
    $form['simplesitemap_settings']['rebuild']['rebuild_submit'] = array(
      '#type' => 'submit',
      '#value' => t('Rebuild sitemap'),
      '#submit' => array('::rebuild_sitemap'),
      '#validate' => array(), // Skip form-level validator.
    );

    return $form;
52 53
  }

54 55 56
  public function rebuild_sitemap(array &$form, FormStateInterface $form_state) {
    $sitemap = new Simplesitemap;
    $sitemap->generate_sitemap();
57 58
  }
}