public function SimpleSitemapDisplayExtender::buildOptionsForm in Simple XML sitemap 8.3
Same name and namespace in other branches
- 4.x 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 105
Class
- SimpleSitemapDisplayExtender
- Simple XML Sitemap display extender plugin.
Namespace
Drupal\simple_sitemap_views\Plugin\views\display_extenderCode
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 => $definition) {
$settings = $this
->getSitemapSettings($variant);
$variant_form =& $form['variants'][$variant];
$variant_form = [
'#type' => 'details',
'#title' => '<em>' . $definition['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' => $definition['label'],
]),
'#default_value' => $settings['index'],
];
$states = [
'visible' => [
':input[name="variants[' . $variant . '][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 valuescan 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';
}
}