You are here

public function SimplesitemapCustomLinksForm::buildForm in Simple XML sitemap 8.3

Same name and namespace in other branches
  1. 8.2 src/Form/SimplesitemapCustomLinksForm.php \Drupal\simple_sitemap\Form\SimplesitemapCustomLinksForm::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

src/Form/SimplesitemapCustomLinksForm.php, line 60

Class

SimplesitemapCustomLinksForm
Class SimplesitemapCustomLinksForm @package Drupal\simple_sitemap\Form

Namespace

Drupal\simple_sitemap\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form['simple_sitemap_custom'] = [
    '#title' => $this
      ->t('Custom links'),
    '#type' => 'fieldset',
    '#markup' => '<div class="description">' . $this
      ->t('Add custom internal drupal paths to the XML sitemap.') . '</div>',
    '#prefix' => FormHelper::getDonationText(),
  ];
  $form['simple_sitemap_custom']['custom_links'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Relative Drupal paths'),
    '#default_value' => $this
      ->customLinksToString($this->generator
      ->setVariants(TRUE)
      ->getCustomLinks(NULL, FALSE)),
    '#description' => $this
      ->t("Please specify drupal internal (relative) paths, one per line. Do not forget to prepend the paths with a '/'.<br>Optionally link priority <em>(0.0 - 1.0)</em> can be added by appending it after a space.<br> Optionally link change frequency <em>(always / hourly / daily / weekly / monthly / yearly / never)</em> can be added by appending it after a space.<br/<br><strong>Examples:</strong><br><em>/ 1.0 daily</em> -> home page with the highest priority and daily change frequency<br><em>/contact</em> -> contact page with the default priority and no change frequency information"),
  ];
  $form['simple_sitemap_custom']['variants'] = [
    '#type' => 'select',
    '#multiple' => TRUE,
    '#title' => $this
      ->t('Sitemap variants'),
    '#description' => $this
      ->t('The sitemap variants to include the above links in.<br>Variants can be configured <a href="@url">here</a>.', [
      '@url' => $GLOBALS['base_url'] . '/admin/config/search/simplesitemap/variants',
    ]),
    '#options' => array_map(function ($variant) {
      return $this
        ->t($variant['label']);
    }, $this->generator
      ->getSitemapManager()
      ->getSitemapVariants(NULL, FALSE)),
    '#default_value' => array_keys(array_filter($this->generator
      ->setVariants(TRUE)
      ->getCustomLinks(NULL, FALSE, TRUE), function ($e) {
      return !empty($e);
    })),
  ];
  $form['simple_sitemap_custom']['include_images'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Include images'),
    '#description' => $this
      ->t('If a custom link points to an entity, include its referenced images in the sitemap.'),
    '#default_value' => $this->generator
      ->getSetting('custom_links_include_images', FALSE),
    '#options' => [
      0 => $this
        ->t('No'),
      1 => $this
        ->t('Yes'),
    ],
  ];
  $this->formHelper
    ->displayRegenerateNow($form['simple_sitemap_custom']);
  return parent::buildForm($form, $form_state);
}