Commit 9ea1c5a7 authored by gbyte.co's avatar gbyte.co Committed by gbyte.co

Issue #3014649 by aspilicious, gbyte.co: Allow multiple variants to be set per bundle via UI

parent 1bbecf32
......@@ -25,7 +25,7 @@ content entity types including:
* ...
Contributed entity types like commerce products or media entities can be indexed
as well. On top of that custom links and view pages can be added to the sitemap.
as well. On top of that custom links and view pages can be added to sitemaps.
To learn about XML sitemaps, see https://en.wikipedia.org/wiki/Sitemaps.
......@@ -46,17 +46,18 @@ The module permission 'administer sitemap settings' can be configured under
### ENTITIES ###
Initially only the home page is indexed in the sitemap. To include content into
the sitemap, visit /admin/config/search/simplesitemap/entities to enable support
for entity types of your choosing. Entity types which feature bundles can then
be configured on a per-bundle basis, e.g.
Initially only the home page is indexed in the default sitemap variant. To
include content into a sitemap, visit
/admin/config/search/simplesitemap/entities to enable support for entity types
of your choosing. Bundleless entity types can be configured right on that page,
for bundles of entity types visit the bundle's configuration pages, e.g.
* /admin/structure/types/manage/[content type] for nodes
* /admin/structure/taxonomy/manage/[taxonomy vocabulary] for taxonomy terms
* /admin/structure/menu/manage/[menu] for menu items
* ...
When including an entity type or bundle into the sitemap, the priority setting
When including an entity type or bundle into a sitemap, the priority setting
can be set which will set the 'priority' parameter for all entities of that
type. Same goes for the 'changefreq' setting. All Images referenced by the
entities can be indexed as well. See https://en.wikipedia.org/wiki/Sitemaps to
......@@ -70,6 +71,10 @@ If you wish for the sitemap to reflect the new configuration instantly, check
'Regenerate sitemaps after clicking save'. This setting only appears if a change
in the settings has been detected.
Once variants are set up in admin/config/search/simplesitemap/variants, all the
above settings can be configured and overwritten on a per variant basis right
from the UI.
As the sitemaps are accessible to anonymous users, bear in mind that only links
will be included which are accessible to anonymous users. There are no access
checks for links added through the module's hooks (see below).
......
......@@ -7,20 +7,22 @@
"use strict";
Drupal.behaviors.simple_sitemapFieldsetSummaries = {
attach: function(context) {
attach: function(context, settings) {
$(context).find('#edit-simple-sitemap').drupalSetSummary(function(context) {
var vals = [];
if ($(context).find('#edit-simple-sitemap-index-content-1').is(':checked')) {
vals.push(Drupal.t('Included in sitemap'));
vals.push(Drupal.t('Variant') + ': ' + $('#edit-simple-sitemap-variant option:selected', context).text());
vals.push(Drupal.t('Priority') + ': ' + $('#edit-simple-sitemap-priority option:selected', context).text());
vals.push(Drupal.t('Change frequency') + ': ' + $('#edit-simple-sitemap-changefreq option:selected', context).text());
vals.push(Drupal.t('Include images') + ': ' + $('#edit-simple-sitemap-include-images option:selected', context).text());
var enabledVariants = [];
$('input:radio.enabled-for-variant').each(function() {
if ($(this).is(':checked') && $(this).val() == 1) {
enabledVariants.push($(this).attr('class').split(' ')[1])
}
});
if (enabledVariants.length > 0) {
return Drupal.t('Included in sitemap variants: ') + enabledVariants.join(', ');
}
else {
vals.push(Drupal.t('Excluded from sitemap'));
return Drupal.t('Excluded from all sitemap variants');
}
return vals.join('<br>');
});
}
};
......
/**
* @file
* Attaches simple_sitemap behaviors to the entity form.
*/
(function($) {
"use strict";
Drupal.behaviors.simple_sitemapForm = {
attach: function(context) {
// On load: Hide the 'Regenerate sitemap' field to only display it if settings have changed.
$('.form-item-simple-sitemap-regenerate-now').hide();
// Show 'Regenerate sitemap' field if settings have changed.
$("#edit-simple-sitemap-index-content"
+ ", #edit-simple-sitemap-variant"
+ ", #edit-simple-sitemap-priority"
+ ", #edit-simple-sitemap-changefreq"
+ ", #edit-simple-sitemap-include-images"
).change(function() {
$('.form-item-simple-sitemap-regenerate-now').show();
});
}
};
})(jQuery);
......@@ -8,46 +8,25 @@
Drupal.behaviors.simple_sitemapSitemapEntities = {
attach: function(context, settings) {
var allEntities = settings.simple_sitemap.all_entities;
var atomicEntities = settings.simple_sitemap.atomic_entities;
$.each(settings.simple_sitemap.all_entities, function(index, entityId) {
var target = '#edit-' + entityId + '-enabled';
triggerVisibility(target, entityId);
// Hide the 'Regenerate sitemap' field to only display it if settings have changed.
$('.form-item-simple-sitemap-regenerate-now').hide();
$.each(allEntities, function(index, value) {
// On load: hide all warning messages.
$('#warning-' + value).hide();
// On change: Show or hide warning message dependent on 'enabled' checkbox.
var enabledId = '#edit-' + value + '-enabled';
$(enabledId).change(function() {
if ($(enabledId).is(':checked')) {
$('#warning-' + value).hide();
$('#indexed-bundles-' + value).show();
}
else {
$('#warning-' + value).show();
$('#indexed-bundles-' + value).hide();
}
// Show 'Regenerate sitemap' field if 'enabled' setting has changed.
$('.form-item-simple-sitemap-regenerate-now').show();
$(target).change(function() {
triggerVisibility(target, entityId);
});
});
// todo
// Show 'Regenerate sitemap' field if settings have changed.
// $.each(atomicEntities, function(index, value) {
// var variant = '.form-item-' + value + '-simple-sitemap-variant';
// var priorityId = '.form-item-' + value + '-simple-sitemap-priority';
// var changefreqId = '.form-item-' + value + '-simple-sitemap-changefreq';
// var includeImagesId = '.form-item-' + value + '-simple-sitemap-include-images';
//
// $(variant, priorityId, changefreqId, includeImagesId).change(function() {
// $('.form-item-simple-sitemap-regenerate-now').show();
// });
// });
function triggerVisibility(target, entityId) {
if ($(target).is(':checked')) {
$('#warning-' + entityId).hide();
$('#indexed-bundles-' + entityId).show();
}
else {
$('#warning-' + entityId).show();
$('#indexed-bundles-' + entityId).hide();
}
}
}
};
})(jQuery);
......@@ -4,12 +4,6 @@ fieldsetSummaries:
js/simple_sitemap.fieldsetSummaries.js: {}
dependencies:
- core/jquery
form:
version: VERSION
js:
js/simple_sitemap.form.js: {}
dependencies:
- core/jquery
sitemapEntities:
version: VERSION
js:
......
......@@ -48,11 +48,6 @@ function simple_sitemap_form_alter(&$form, FormStateInterface $form_state, $form
'#weight' => 10,
];
// Attach some js magic to forms.
if ($f->getEntityCategory() !== 'instance') {
$form['#attached']['library'][] = 'simple_sitemap/form';
}
// Only attach fieldset summary js to 'additional settings' vertical tabs.
if (isset($form['additional_settings'])) {
$form['#attached']['library'][] = 'simple_sitemap/fieldsetSummaries';
......@@ -103,42 +98,41 @@ function simple_sitemap_entity_form_submit($form, FormStateInterface &$form_stat
/** @var \Drupal\simple_sitemap\Simplesitemap $generator */
$generator = \Drupal::service('simple_sitemap.generator');
// Only save other values if indexing is enabled.
if ($settings['index'] = (bool) $values['simple_sitemap_index_content']) {
$settings['priority'] = $values['simple_sitemap_priority'];
$settings['changefreq'] = $values['simple_sitemap_changefreq'];
$settings['include_images'] = (bool) $values['simple_sitemap_include_images'];
}
// Deleting bundle settings for old bundle.
// See SimplesitemapEntitiesForm::submitForm().
// todo: Not necessary once https://www.drupal.org/project/simple_sitemap/issues/3014649 is implemented.
if (isset($form['simple_sitemap']['simple_sitemap_variant']['#default_value'])) {
$old_variant = $form['simple_sitemap']['simple_sitemap_variant']['#default_value'];
if ($old_variant !== $values['simple_sitemap_variant']) {
$generator->setVariants($old_variant)->removeBundleSettings($f->getEntityTypeId(), $f->getBundleName());
foreach ($generator->getSitemapManager()->getSitemapVariants(NULL, FALSE) as $variant => $definition) {
if (isset($values['index_' . $variant . '_' . $f->getEntityTypeId() . '_settings'])) { // Variants may have changed since form load.
$settings = [
'index' => (bool) $values['index_' . $variant . '_' . $f->getEntityTypeId() . '_settings'],
'priority' => $values['priority_' . $variant . '_' . $f->getEntityTypeId() . '_settings'],
'changefreq' => $values['changefreq_' . $variant . '_' . $f->getEntityTypeId() . '_settings'],
'include_images' => (bool) $values['include_images_' . $variant . '_' . $f->getEntityTypeId() . '_settings'],
];
$generator->setVariants($variant);
switch ($f->getEntityCategory()) {
case 'bundle':
$generator->setBundleSettings($f->getEntityTypeId(),
!empty($f->getBundleName()) ? $f->getBundleName() : $f->getFormEntityId(),
$settings
);
if (empty($settings['index'])) {
$generator->removeEntityInstanceSettings($f->getEntityTypeId(), $f->getInstanceId());
}
break;
case 'instance':
$generator->setEntityInstanceSettings($f->getEntityTypeId(),
!empty($f->getInstanceId()) ? $f->getInstanceId() : $f->getFormEntityId(),
$settings
);
break;
}
}
}
switch ($f->getEntityCategory()) {
case 'bundle':
$generator->setVariants($values['simple_sitemap_variant'])
->setBundleSettings($f->getEntityTypeId(),
!empty($f->getBundleName()) ? $f->getBundleName() : $f->getFormEntityId(),
$settings
);
break;
case 'instance':
$generator->setVariants($values['simple_sitemap_variant'])
->setEntityInstanceSettings($f->getEntityTypeId(),
!empty($f->getInstanceId()) ? $f->getInstanceId() : $f->getFormEntityId(),
$settings
);
break;
}
// Regenerate sitemaps according to user setting.
if ($values['simple_sitemap_regenerate_now']) {
$generator->rebuildQueue()->generateSitemap();
......
administer sitemap settings:
title: 'Administer sitemap settings'
description: 'Administer Simple XML Sitemap settings, alter inclusion settings of content and generate the sitemap on demand.'
description: 'Administer Simple XML Sitemap settings, alter inclusion settings of content and generate sitemaps on demand.'
restrict access: false
......@@ -59,6 +59,7 @@ services:
arguments:
- '@entity_type.manager'
- '@database'
- '@entity_type.bundle.info'
simple_sitemap.form_helper:
class: Drupal\simple_sitemap\Form\FormHelper
......
......@@ -4,6 +4,7 @@ namespace Drupal\simple_sitemap;
use Drupal\Core\Entity\ContentEntityTypeInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Database\Connection;
use Drupal\Core\Url;
......@@ -29,17 +30,30 @@ class EntityHelper {
*/
protected $db;
/**
* @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
*/
protected $entityTypeBundleInfo;
/**
* EntityHelper constructor.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* @param \Drupal\Core\Database\Connection $database
* The current active database's master connection.
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
*/
public function __construct(EntityTypeManagerInterface $entityTypeManager, Connection $database) {
$this->entityTypeManager = $entityTypeManager;
public function __construct(EntityTypeManagerInterface $entity_type_manager, Connection $database, EntityTypeBundleInfoInterface $entity_type_bundle_info) {
$this->entityTypeManager = $entity_type_manager;
$this->db = $database;
$this->entityTypeBundleInfo = $entity_type_bundle_info;
}
/**
* @param string $entity_type_name
* @param string $bundle_name
* @return mixed
*/
public function getBundleLabel($entity_type_name, $bundle_name) {
return $this->entityTypeBundleInfo->getBundleInfo($entity_type_name)[$bundle_name]['label'];
}
/**
......
......@@ -60,15 +60,13 @@ class FormHelper {
protected $instanceId;
/**
* @var string
* @var array
*/
protected $variant;
protected $settings;
/**
* @var array
*/
protected $bundleSettings;
protected static $allowedFormOperations = [
'default',
'edit',
......@@ -76,6 +74,9 @@ class FormHelper {
'register',
];
/**
* @var array
*/
protected static $changefreqValues = [
'always',
'hourly',
......@@ -86,15 +87,6 @@ class FormHelper {
'never',
];
protected static $valuesToCheck = [
'simple_sitemap_variant',
'simple_sitemap_index_content',
'simple_sitemap_priority',
'simple_sitemap_changefreq',
'simple_sitemap_include_images',
'simple_sitemap_regenerate_now',
];
/**
* FormHelper constructor.
* @param \Drupal\simple_sitemap\Simplesitemap $generator
......@@ -114,12 +106,15 @@ class FormHelper {
/**
* @param \Drupal\Core\Form\FormStateInterface $form_state
* @return bool
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*
*/
public function processForm(FormStateInterface $form_state) {
$this->formState = $form_state;
$this->cleanUpFormInfo();
$this->getEntityDataFromFormEntity();
$this->negotiateVariant();
$this->negotiateSettings();
return $this->supports();
}
......@@ -146,6 +141,7 @@ class FormHelper {
*/
public function setEntityTypeId($entity_type_id) {
$this->entityTypeId = $entity_type_id;
return $this;
}
......@@ -162,6 +158,7 @@ class FormHelper {
*/
public function setBundleName($bundle_name) {
$this->bundleName = $bundle_name;
return $this;
}
......@@ -178,6 +175,7 @@ class FormHelper {
*/
public function setInstanceId($instance_id) {
$this->instanceId = $instance_id;
return $this;
}
......@@ -208,16 +206,6 @@ class FormHelper {
return FALSE;
}
// Do not alter the form, if sitemap is disabled for the entity type of this
// entity instance.
elseif ($this->getEntityCategory() === 'instance') {
if (NULL === $this->variant || !$this->generator
->setVariants($this->variant)
->bundleIsIndexed($this->getEntityTypeId(), $this->getBundleName())) {
return FALSE;
}
}
return TRUE;
}
......@@ -228,12 +216,12 @@ class FormHelper {
public function displayRegenerateNow(&$form_fragment) {
$form_fragment['simple_sitemap_regenerate_now'] = [
'#type' => 'checkbox',
'#title' => $this->t('Regenerate sitemap after hitting <em>Save</em>'),
'#title' => $this->t('Regenerate all sitemaps after hitting <em>Save</em>'),
'#description' => $this->t('This setting will regenerate all sitemaps including the above changes.'),
'#default_value' => FALSE,
];
if ($this->generator->getSetting('cron_generate')) {
$form_fragment['simple_sitemap_regenerate_now']['#description'] .= '<br>' . $this->t('Otherwise the sitemap will be regenerated during a future cron run.');
$form_fragment['simple_sitemap_regenerate_now']['#description'] .= '<br>' . $this->t('Otherwise the sitemaps will be regenerated during a future cron run.');
}
return $this;
......@@ -241,131 +229,124 @@ class FormHelper {
/**
* @return $this
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
public function negotiateVariant() {
$all_bundle_settings = $this->generator->setVariants(TRUE)
->getBundleSettings($this->getEntityTypeId(), $this->getBundleName(), FALSE, TRUE);
$this->bundleSettings = NULL !== ($variant = key($all_bundle_settings))
? $all_bundle_settings[$variant]
: [];
$this->variant = $variant;
public function negotiateSettings() {
$this->settings = $this->generator->setVariants(TRUE)
->getBundleSettings($this->getEntityTypeId(), $this->getBundleName(), TRUE, TRUE);
if ($this->getEntityCategory() === 'instance') {
//todo Should spit out variant => settings and not just settings; to do this, alter getEntityInstanceSettings() to include 'multiple variants' option.
foreach ($this->settings as $variant_name => $settings) {
if (NULL !== $instance_id = $this->getInstanceId()) {
$this->settings[$variant_name] = $this->generator->setVariants($variant_name)
->getEntityInstanceSettings($this->getEntityTypeId(), $instance_id);
}
$this->settings[$variant_name]['bundle_settings'] = $settings;
}
}
return $this;
}
/**
* @param array $form_fragment
* @param bool $multiple
* @param $form_fragment
* @return $this
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
public function displayEntitySettings(&$form_fragment, $multiple = FALSE) {
$prefix = $multiple ? $this->getEntityTypeId() . '_' : '';
$settings = $this->getEntityCategory() === 'instance' && NULL !== $this->variant && NULL !== $this->getInstanceId()
? $this->generator->setVariants($this->variant)->getEntityInstanceSettings($this->getEntityTypeId(), $this->getInstanceId())
: $this->bundleSettings;
Simplesitemap::supplementDefaultSettings('entity', $settings);
public function displayEntitySettings(&$form_fragment) {
$bundle_name = !empty($this->getBundleName())
? $this->entityHelper->getBundleLabel($this->getEntityTypeId(), $this->getBundleName())
: $this->t('undefined');
$variants = $this->generator->getSitemapManager()->getSitemapVariants(NULL, FALSE);
$form_fragment['settings']['#markup'] = empty($variants)
? $this->t('At least one sitemap variants needs to be defined for a bundle to be indexable.<br>Variants can be configured <a href="@url">here</a>.', ['@url' => $GLOBALS['base_url'] . '/admin/config/search/simplesitemap/variants'])
: '<strong>' . $this->t('Sitemap variants') . '</strong>';
foreach ($variants as $variant => $definition) {
$form_fragment['settings'][$variant] = [
'#type' => 'details',
'#title' => '<em>' . $this->t($definition['label']) . '</em>',
'#open' => !empty($this->settings[$variant]['index']),
];
$bundle_name = !empty($this->getBundleName()) ? $this->getBundleName() : $this->t('undefined');
// Disable fields of entity instance whose bundle is not indexed.
$form_fragment['settings'][$variant]['#disabled'] = $this->getEntityCategory() === 'instance' && empty($this->settings[$variant]['bundle_settings']['index']);
// Index
if (!$multiple) {
$form_fragment[$prefix . 'simple_sitemap_index_content'] = [
// Index
$form_fragment['settings'][$variant]['index_' . $variant . '_' . $this->getEntityTypeId() . '_settings'] = [
'#type' => 'radios',
'#default_value' => (int) $settings['index'],
'#default_value' => (int) $this->settings[$variant]['index'],
'#options' => [
0 => $this->getEntityCategory() === 'instance'
? $this->t('Do not index this @bundle entity', ['@bundle' => $bundle_name])
: $this->t('Do not index entities of this type'),
1 => $this->getEntityCategory() === 'instance'
? $this->t('Index this @bundle entity', ['@bundle' => $bundle_name])
: $this->t('Index entities of this type'),
$this->getEntityCategory() === 'instance'
? $this->t('Do not index this <em>@bundle</em> entity in variant <em>@variant_label</em>', ['@bundle' => $bundle_name, '@variant_label' => $this->t($variants[$variant]['label'])])
: $this->t('Do not index entities of type <em>@bundle</em> in variant <em>@variant_label</em>', ['@bundle' => $bundle_name, '@variant_label' => $this->t($variants[$variant]['label'])]),
$this->getEntityCategory() === 'instance'
? $this->t('Index this <em>@bundle entity</em> in variant <em>@variant_label</em>', ['@bundle' => $bundle_name, '@variant_label' => $this->t($variants[$variant]['label'])])
: $this->t('Index entities of type <em>@bundle</em> in variant <em>@variant_label</em>', ['@bundle' => $bundle_name, '@variant_label' => $this->t($variants[$variant]['label'])]),
],
'#attributes' => ['class' => ['enabled-for-variant', $variant]],
];
if ($this->getEntityCategory() === 'instance' && isset($this->bundleSettings['index'])) {
$form_fragment[$prefix . 'simple_sitemap_index_content']['#options'][(int) $this->bundleSettings['index']] .= ' <em>(' . $this->t('default') . ')</em>';
if ($this->getEntityCategory() === 'instance' && isset($this->settings[$variant]['bundle_settings']['index'])) {
$form_fragment['settings'][$variant]['index_' . $variant . '_' . $this->getEntityTypeId() . '_settings']['#options'][(int) $this->settings[$variant]['bundle_settings']['index']] .= ' <em>(' . $this->t('default') . ')</em>';
}
}
// Variant
$form_fragment[$prefix . 'simple_sitemap_variant'] = [
'#type' => 'select',
'#title' => $this->t('Sitemap variant'),
'#description' => $this->t('The sitemap variant entities of this type are to be indexed in.'),
'#options' => $this->getVariantSelectValues(),
'#default_value' => $this->getVariantSelectValuesDefault($this->variant),
'#states' => [
'visible' => !$multiple
? [':input[name="' . $prefix . 'simple_sitemap_index_content"]' => ['value' => 1]]
: [':input[name="' . $prefix . 'enabled"]' => ['checked' => TRUE]],
'required' => !$multiple // todo Should implement server side validation on top of this.
? [':input[name="' . $prefix . 'simple_sitemap_index_content"]' => ['value' => 1]]
: [':input[name="' . $prefix . 'enabled"]' => ['checked' => TRUE]],
],
'#disabled' => $this->getEntityCategory() === 'instance',
];
// Priority
$form_fragment[$prefix . 'simple_sitemap_priority'] = [
'#type' => 'select',
'#title' => $this->t('Priority'),
'#description' => $this->getEntityCategory() === 'instance'
? $this->t('The priority this @bundle entity will have in the eyes of search engine bots.', ['@bundle' => $bundle_name])
: $this->t('The priority entities of this type will have in the eyes of search engine bots.'),
'#default_value' => $settings['priority'],
'#options' => $this->getPrioritySelectValues(),
'#states' => [
'visible' => !$multiple
? [':input[name="' . $prefix . 'simple_sitemap_index_content"]' => ['value' => 1]]
: [':input[name="' . $prefix . 'enabled"]' => ['checked' => TRUE]],
],
];
// Priority
$form_fragment['settings'][$variant]['priority_' . $variant . '_' . $this->getEntityTypeId() . '_settings'] = [
'#type' => 'select',
'#title' => $this->t('Priority'),
'#description' => $this->getEntityCategory() === 'instance'
? $this->t('The priority this <em>@bundle</em> entity will have in the eyes of search engine bots.', ['@bundle' => $bundle_name])
: $this->t('The priority entities of this type will have in the eyes of search engine bots.'),
'#default_value' => $this->settings[$variant]['priority'],
'#options' => $this->getPrioritySelectValues(),
'#states' => [
'visible' => [':input[name="index_' . $variant . '_' . $this->getEntityTypeId() . '_settings"]' => ['value' => 1]],
],
];
if ($this->getEntityCategory() === 'instance' && isset($this->bundleSettings['priority'])) {
$form_fragment[$prefix . 'simple_sitemap_priority']['#options'][$this->formatPriority($this->bundleSettings['priority'])] .= ' (' . $this->t('default') . ')';
}
if ($this->getEntityCategory() === 'instance' && isset($this->settings[$variant]['bundle_settings']['priority'])) {
$form_fragment['settings'][$variant]['priority_' . $variant . '_' . $this->getEntityTypeId() . '_settings']['#options'][$this->formatPriority($this->settings[$variant]['bundle_settings']['priority'])] .= ' (' . $this->t('default') . ')';
}
// Changefreq
$form_fragment[$prefix . 'simple_sitemap_changefreq'] = [
'#type' => 'select',
'#title' => $this->t('Change frequency'),
'#description' => $this->getEntityCategory() === 'instance'
? $this->t('The frequency with which this @bundle entity changes. Search engine bots may take this as an indication of how often to index it.', ['@bundle' => $bundle_name])
: $this->t('The frequency with which entities of this type change. Search engine bots may take this as an indication of how often to index them.'),
'#default_value' => $settings['changefreq'],
'#options' => $this->getChangefreqSelectValues(),
'#states' => [
'visible' => !$multiple
? [':input[name="' . $prefix . 'simple_sitemap_index_content"]' => ['value' => 1]]
: [':input[name="' . $prefix . 'enabled"]' => ['checked' => TRUE]],
],
];
// Changefreq
$form_fragment['settings'][$variant]['changefreq_' . $variant . '_' . $this->getEntityTypeId() . '_settings'] = [
'#type' => 'select',
'#title' => $this->t('Change frequency'),
'#description' => $this->getEntityCategory() === 'instance'
? $this->t('The frequency with which this <em>@bundle</em> entity changes. Search engine bots may take this as an indication of how often to index it.', ['@bundle' => $bundle_name])
: $this->t('The frequency with which entities of this type change. Search engine bots may take this as an indication of how often to index them.'),
'#default_value' => $this->settings[$variant]['changefreq'],
'#options' => $this->getChangefreqSelectValues(),
'#states' => [
'visible' => [':input[name="index_' . $variant . '_' . $this->getEntityTypeId() . '_settings"]' => ['value' => 1]],
],
];
if ($this->getEntityCategory() === 'instance' && isset($this->bundleSettings['changefreq'])) {
$form_fragment[$prefix . 'simple_sitemap_changefreq']['#options'][$this->bundleSettings['changefreq']] .= ' (' . $this->t('default') . ')';
}
if ($this->getEntityCategory() === 'instance' && isset($this->settings[$variant]['bundle_settings']['changefreq'])) {
$form_fragment['settings'][$variant]['changefreq_' . $variant . '_' . $this->getEntityTypeId() . '_settings']['#options'][$this->settings[$variant]['bundle_settings']['changefreq']] .= ' (' . $this->t('default') . ')';
}
// Images
$form_fragment[$prefix . 'simple_sitemap_include_images'] = [
'#type' => 'select',
'#title' => $this->t('Include images'),
'#description' => $this->getEntityCategory() === 'instance'
? $this->t('Determines if images referenced by this @bundle entity should be included in the sitemap.', ['@bundle' => $bundle_name])
: $this->t('Determines if images referenced by entities of this type should be included in the sitemap.'),
'#default_value' => (int) $settings['include_images'],
'#options' => [0 => $this->t('No'), 1 => $this->t('Yes')],
'#states' => [
'visible' => !$multiple
? [':input[name="' . $prefix . 'simple_sitemap_index_content"]' => ['value' => 1]]
: [':input[name="' . $prefix . 'enabled"]' => ['checked' => TRUE]],
],
];
// Images
$form_fragment['settings'][$variant]['include_images_' . $variant . '_' . $this->getEntityTypeId() . '_settings'] = [
'#type' => 'select',
'#title' => $this->t('Include images'),
'#description' => $this->getEntityCategory() === 'instance'
? $this->t('Determines if images referenced by this <em>@bundle</em> entity should be included in the sitemap.', ['@bundle' => $bundle_name])
: $this->t('Determines if images referenced by entities of this type should be included in the sitemap.'),
'#default_value' => (int) $this->settings[$variant]['include_images'],
'#options' => [$this->t('No'), $this->t('Yes')],
'#states' => [
'visible' => [':input[name="index_' . $variant . '_' . $this->getEntityTypeId() . '_settings"]' => ['value' => 1]],
],
];
if ($this->getEntityCategory() === 'instance' && isset($this->bundleSettings['include_images'])) {
$form_fragment[$prefix . 'simple_sitemap_include_images']['#options'][(int) $this->bundleSettings['include_images']] .= ' (' . $this->t('default') . ')';
if ($this->getEntityCategory() === 'instance' && isset($this->settings[$variant]['bundle_settings']['include_images'])) {
$form_fragment['settings'][$variant]['include_images_' . $variant . '_' . $this->getEntityTypeId() . '_settings']['#options'][(int) $this->settings[$variant]['bundle_settings']['include_images']] .= ' (' . $this->t('default') . ')';
}
}
return $this;
......@@ -452,8 +433,7 @@ class FormHelper {
$this->entityTypeId = NULL;
$this->bundleName = NULL;
$this->instanceId = NULL;
$this->variant = NULL;
$this->bundleSettings = NULL;
$this->settings = NULL;
return $this;
}
......@@ -480,14 +460,17 @@ class FormHelper {
* TRUE if simple_sitemap form values have been altered by the user.
*/
public function valuesChanged($form, array $values) {
foreach (self::$valuesToCheck as $field_name) {
if (!isset($form['simple_sitemap'][$field_name]['#default_value'])
|| (isset($values[$field_name]) && $values[$field_name] != $form['simple_sitemap'][$field_name]['#default_value'])) {
return TRUE;
}
}
return FALSE;
// foreach (self::$valuesToCheck as $field_name) {
// if (!isset($form['simple_sitemap'][$field_name]['#default_value'])
// || (isset($values[$field_name]) && $values[$field_name] != $form['simple_sitemap'][$field_name]['#default_value'])) {
// return TRUE;
// }
// }
//
// return FALSE;
//todo
return TRUE;
}
/**
......
......@@ -70,18 +70,27 @@ class SimplesitemapEntitiesForm extends SimplesitemapFormBase {
$form['#attached']['library'][] = 'simple_sitemap/sitemapEntities';