You are here

public function SimpleSitemapDisplayExtender::buildOptionsForm in Simple XML sitemap 4.x

Same name and namespace in other branches
  1. 8.3 modules/simple_sitemap_views/src/Plugin/views/display_extender/SimpleSitemapDisplayExtender.php \Drupal\simple_sitemap_views\Plugin\views\display_extender\SimpleSitemapDisplayExtender::buildOptionsForm()

Provide a form to edit options for this plugin.

Overrides DisplayExtenderPluginBase::buildOptionsForm

File

modules/simple_sitemap_views/src/Plugin/views/display_extender/SimpleSitemapDisplayExtender.php, line 94

Class

SimpleSitemapDisplayExtender
Simple XML Sitemap display extender plugin.

Namespace

Drupal\simple_sitemap_views\Plugin\views\display_extender

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
  if ($this
    ->hasSitemapSettings() && $form_state
    ->get('section') == 'simple_sitemap') {
    $has_required_arguments = $this
      ->hasRequiredArguments();
    $arguments_options = $this
      ->getArgumentsOptions();
    $form['variants'] = [
      '#type' => 'container',
      '#tree' => TRUE,
    ];
    foreach ($this->variants as $variant_id => $variant) {
      $settings = $this
        ->getSitemapSettings($variant_id);
      $variant_form =& $form['variants'][$variant_id];
      $variant_form = [
        '#type' => 'details',
        '#title' => '<em>' . $variant
          ->label() . '</em>',
        '#open' => (bool) $settings['index'],
      ];
      $variant_form['index'] = [
        '#type' => 'checkbox',
        '#title' => $this
          ->t('Index this display in variant <em>@variant_label</em>', [
          '@variant_label' => $variant
            ->label(),
        ]),
        '#default_value' => $settings['index'],
      ];
      $states = [
        'visible' => [
          ':input[name="variants[' . $variant_id . '][index]"]' => [
            'checked' => TRUE,
          ],
        ],
      ];

      // The sitemap priority.
      $variant_form['priority'] = [
        '#type' => 'select',
        '#title' => $this
          ->t('Priority'),
        '#description' => $this
          ->t('The priority this display will have in the eyes of search engine bots.'),
        '#default_value' => $settings['priority'],
        '#options' => $this->formHelper
          ->getPrioritySelectValues(),
        '#states' => $states,
      ];

      // The sitemap change frequency.
      $variant_form['changefreq'] = [
        '#type' => 'select',
        '#title' => $this
          ->t('Change frequency'),
        '#description' => $this
          ->t('The frequency with which this display changes. Search engine bots may take this as an indication of how often to index it.'),
        '#default_value' => $settings['changefreq'],
        '#options' => $this->formHelper
          ->getChangefreqSelectValues(),
        '#states' => $states,
      ];

      // Arguments to index.
      $variant_form['arguments'] = [
        '#type' => 'checkboxes',
        '#title' => $this
          ->t('Indexed arguments'),
        '#options' => $arguments_options,
        '#default_value' => $settings['arguments'],
        '#attributes' => [
          'class' => [
            'indexed-arguments',
          ],
        ],
        '#access' => !empty($arguments_options),
        '#states' => $states,
      ];

      // Required arguments are always indexed.
      foreach ($this
        ->getRequiredArguments() as $argument_id) {
        $variant_form['arguments'][$argument_id]['#disabled'] = TRUE;
      }

      // Max links with arguments.
      $variant_form['max_links'] = [
        '#type' => 'number',
        '#title' => $this
          ->t('Maximum display variations'),
        '#description' => $this
          ->t('The maximum number of link variations to be indexed for this display. If left blank, each argument will create link variations for this display. Use with caution, as a large number of argument values​can significantly increase the number of sitemap links.'),
        '#default_value' => $settings['max_links'],
        '#min' => 1,
        '#access' => !empty($arguments_options) || $has_required_arguments,
        '#states' => $states,
      ];
    }
    $form['#title'] .= $this
      ->t('Simple XML Sitemap settings for this display');
    $form['#attached']['library'][] = 'simple_sitemap_views/viewsUi';
  }
}