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: ...@@ -25,7 +25,7 @@ content entity types including:
* ... * ...
Contributed entity types like commerce products or media entities can be indexed 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. 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 ...@@ -46,17 +46,18 @@ The module permission 'administer sitemap settings' can be configured under
### ENTITIES ### ### ENTITIES ###
Initially only the home page is indexed in the sitemap. To include content into Initially only the home page is indexed in the default sitemap variant. To
the sitemap, visit /admin/config/search/simplesitemap/entities to enable support include content into a sitemap, visit
for entity types of your choosing. Entity types which feature bundles can then /admin/config/search/simplesitemap/entities to enable support for entity types
be configured on a per-bundle basis, e.g. 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/types/manage/[content type] for nodes
* /admin/structure/taxonomy/manage/[taxonomy vocabulary] for taxonomy terms * /admin/structure/taxonomy/manage/[taxonomy vocabulary] for taxonomy terms
* /admin/structure/menu/manage/[menu] for menu items * /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 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 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 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 ...@@ -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 'Regenerate sitemaps after clicking save'. This setting only appears if a change
in the settings has been detected. 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 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 will be included which are accessible to anonymous users. There are no access
checks for links added through the module's hooks (see below). checks for links added through the module's hooks (see below).
......
...@@ -7,20 +7,22 @@ ...@@ -7,20 +7,22 @@
"use strict"; "use strict";
Drupal.behaviors.simple_sitemapFieldsetSummaries = { Drupal.behaviors.simple_sitemapFieldsetSummaries = {
attach: function(context) { attach: function(context, settings) {
$(context).find('#edit-simple-sitemap').drupalSetSummary(function(context) { $(context).find('#edit-simple-sitemap').drupalSetSummary(function(context) {
var vals = []; var enabledVariants = [];
if ($(context).find('#edit-simple-sitemap-index-content-1').is(':checked')) { $('input:radio.enabled-for-variant').each(function() {
vals.push(Drupal.t('Included in sitemap')); if ($(this).is(':checked') && $(this).val() == 1) {
vals.push(Drupal.t('Variant') + ': ' + $('#edit-simple-sitemap-variant option:selected', context).text()); enabledVariants.push($(this).attr('class').split(' ')[1])
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());
if (enabledVariants.length > 0) {
return Drupal.t('Included in sitemap variants: ') + enabledVariants.join(', ');
} }
else { 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 @@ ...@@ -8,46 +8,25 @@
Drupal.behaviors.simple_sitemapSitemapEntities = { Drupal.behaviors.simple_sitemapSitemapEntities = {
attach: function(context, settings) { attach: function(context, settings) {
var allEntities = settings.simple_sitemap.all_entities; $.each(settings.simple_sitemap.all_entities, function(index, entityId) {
var atomicEntities = settings.simple_sitemap.atomic_entities; var target = '#edit-' + entityId + '-enabled';
triggerVisibility(target, entityId);
// Hide the 'Regenerate sitemap' field to only display it if settings have changed. $(target).change(function() {
$('.form-item-simple-sitemap-regenerate-now').hide(); triggerVisibility(target, entityId);
$.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();
}); });
}); });
// todo function triggerVisibility(target, entityId) {
// Show 'Regenerate sitemap' field if settings have changed. if ($(target).is(':checked')) {
// $.each(atomicEntities, function(index, value) { $('#warning-' + entityId).hide();
// var variant = '.form-item-' + value + '-simple-sitemap-variant'; $('#indexed-bundles-' + entityId).show();
// var priorityId = '.form-item-' + value + '-simple-sitemap-priority'; }
// var changefreqId = '.form-item-' + value + '-simple-sitemap-changefreq'; else {
// var includeImagesId = '.form-item-' + value + '-simple-sitemap-include-images'; $('#warning-' + entityId).show();
// $('#indexed-bundles-' + entityId).hide();
// $(variant, priorityId, changefreqId, includeImagesId).change(function() { }
// $('.form-item-simple-sitemap-regenerate-now').show(); }
// });
// });
} }
}; };
})(jQuery); })(jQuery);
...@@ -4,12 +4,6 @@ fieldsetSummaries: ...@@ -4,12 +4,6 @@ fieldsetSummaries:
js/simple_sitemap.fieldsetSummaries.js: {} js/simple_sitemap.fieldsetSummaries.js: {}
dependencies: dependencies:
- core/jquery - core/jquery
form:
version: VERSION
js:
js/simple_sitemap.form.js: {}
dependencies:
- core/jquery
sitemapEntities: sitemapEntities:
version: VERSION version: VERSION
js: js:
......
...@@ -48,11 +48,6 @@ function simple_sitemap_form_alter(&$form, FormStateInterface $form_state, $form ...@@ -48,11 +48,6 @@ function simple_sitemap_form_alter(&$form, FormStateInterface $form_state, $form
'#weight' => 10, '#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. // Only attach fieldset summary js to 'additional settings' vertical tabs.
if (isset($form['additional_settings'])) { if (isset($form['additional_settings'])) {
$form['#attached']['library'][] = 'simple_sitemap/fieldsetSummaries'; $form['#attached']['library'][] = 'simple_sitemap/fieldsetSummaries';
...@@ -103,42 +98,41 @@ function simple_sitemap_entity_form_submit($form, FormStateInterface &$form_stat ...@@ -103,42 +98,41 @@ function simple_sitemap_entity_form_submit($form, FormStateInterface &$form_stat
/** @var \Drupal\simple_sitemap\Simplesitemap $generator */ /** @var \Drupal\simple_sitemap\Simplesitemap $generator */
$generator = \Drupal::service('simple_sitemap.generator'); $generator = \Drupal::service('simple_sitemap.generator');
// Only save other values if indexing is enabled. foreach ($generator->getSitemapManager()->getSitemapVariants(NULL, FALSE) as $variant => $definition) {
if ($settings['index'] = (bool) $values['simple_sitemap_index_content']) {
$settings['priority'] = $values['simple_sitemap_priority']; if (isset($values['index_' . $variant . '_' . $f->getEntityTypeId() . '_settings'])) { // Variants may have changed since form load.
$settings['changefreq'] = $values['simple_sitemap_changefreq']; $settings = [
$settings['include_images'] = (bool) $values['simple_sitemap_include_images']; 'index' => (bool) $values['index_' . $variant . '_' . $f->getEntityTypeId() . '_settings'],
} 'priority' => $values['priority_' . $variant . '_' . $f->getEntityTypeId() . '_settings'],
'changefreq' => $values['changefreq_' . $variant . '_' . $f->getEntityTypeId() . '_settings'],
// Deleting bundle settings for old bundle. 'include_images' => (bool) $values['include_images_' . $variant . '_' . $f->getEntityTypeId() . '_settings'],
// 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'])) { $generator->setVariants($variant);
$old_variant = $form['simple_sitemap']['simple_sitemap_variant']['#default_value'];
if ($old_variant !== $values['simple_sitemap_variant']) { switch ($f->getEntityCategory()) {
$generator->setVariants($old_variant)->removeBundleSettings($f->getEntityTypeId(), $f->getBundleName());
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. // Regenerate sitemaps according to user setting.
if ($values['simple_sitemap_regenerate_now']) { if ($values['simple_sitemap_regenerate_now']) {
$generator->rebuildQueue()->generateSitemap(); $generator->rebuildQueue()->generateSitemap();
......
administer sitemap settings: administer sitemap settings:
title: '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 restrict access: false
...@@ -59,6 +59,7 @@ services: ...@@ -59,6 +59,7 @@ services:
arguments: arguments:
- '@entity_type.manager' - '@entity_type.manager'
- '@database' - '@database'
- '@entity_type.bundle.info'
simple_sitemap.form_helper: simple_sitemap.form_helper:
class: Drupal\simple_sitemap\Form\FormHelper class: Drupal\simple_sitemap\Form\FormHelper
......
...@@ -4,6 +4,7 @@ namespace Drupal\simple_sitemap; ...@@ -4,6 +4,7 @@ namespace Drupal\simple_sitemap;
use Drupal\Core\Entity\ContentEntityTypeInterface; use Drupal\Core\Entity\ContentEntityTypeInterface;
use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Database\Connection; use Drupal\Core\Database\Connection;
use Drupal\Core\Url; use Drupal\Core\Url;
...@@ -29,17 +30,30 @@ class EntityHelper { ...@@ -29,17 +30,30 @@ class EntityHelper {
*/ */
protected $db; protected $db;
/**
* @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
*/
protected $entityTypeBundleInfo;
/** /**
* EntityHelper constructor. * EntityHelper constructor.
* * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager.
* @param \Drupal\Core\Database\Connection $database * @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) { public function __construct(EntityTypeManagerInterface $entity_type_manager, Connection $database, EntityTypeBundleInfoInterface $entity_type_bundle_info) {
$this->entityTypeManager = $entityTypeManager; $this->entityTypeManager = $entity_type_manager;
$this->db = $database; $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'];
} }
/** /**
......
This diff is collapsed.
...@@ -70,18 +70,27 @@ class SimplesitemapEntitiesForm extends SimplesitemapFormBase { ...@@ -70,18 +70,27 @@ class SimplesitemapEntitiesForm extends SimplesitemapFormBase {
$form['#attached']['library'][] = 'simple_sitemap/sitemapEntities'; $form['#attached']['library'][] = 'simple_sitemap/sitemapEntities';
$form['#attached']['drupalSettings']['simple_sitemap'] = ['all_entities' => [], 'atomic_entities' => []]; $form['#attached']['drupalSettings']['simple_sitemap'] = ['all_entities' => [], 'atomic_entities' => []];
$variants = $this->generator->getSitemapManager()->getSitemapVariants(NULL, FALSE);
$all_bundle_settings = $this->generator->setVariants(TRUE)->getBundleSettings(NULL, NULL, TRUE, TRUE);
$indexed_bundles = [];
foreach ($all_bundle_settings as $variant => $entity_types) {
foreach ($entity_types as $entity_type_name => $bundles) {
foreach ($bundles as $bundle_name => $bundle_settings) {
if (!empty($bundle_settings['index'])) {
$indexed_bundles[$entity_type_name][$bundle_name]['variants'][] = $this->t($variants[$variant]['label']);
$indexed_bundles[$entity_type_name][$bundle_name]['bundle_label'] = $this->entityHelper->getBundleLabel($entity_type_name, $bundle_name);
}
}
}
}
$entity_type_labels = []; $entity_type_labels = [];
foreach ($this->entityHelper->getSupportedEntityTypes() as $entity_type_id => $entity_type) { foreach ($this->entityHelper->getSupportedEntityTypes() as $entity_type_id => $entity_type) {
$entity_type_labels[$entity_type_id] = $entity_type->getLabel() ? : $entity_type_id; $entity_type_labels[$entity_type_id] = $entity_type->getLabel() ? : $entity_type_id;
} }
asort($entity_type_labels); asort($entity_type_labels);
$this->formHelper->processForm($form_state);
$bundle_settings = $this->generator->getBundleSettings();
foreach ($entity_type_labels as $entity_type_id => $entity_type_label) { foreach ($entity_type_labels as $entity_type_id => $entity_type_label) {
;
$enabled_entity_type = $this->generator->entityTypeIsEnabled($entity_type_id); $enabled_entity_type = $this->generator->entityTypeIsEnabled($entity_type_id);
$atomic_entity_type = $this->entityHelper->entityTypeIsAtomic($entity_type_id); $atomic_entity_type = $this->entityHelper->entityTypeIsAtomic($entity_type_id);
$css_entity_type_id = str_replace('_', '-', $entity_type_id); $css_entity_type_id = str_replace('_', '-', $entity_type_id);
...@@ -94,34 +103,36 @@ class SimplesitemapEntitiesForm extends SimplesitemapFormBase { ...@@ -94,34 +103,36 @@ class SimplesitemapEntitiesForm extends SimplesitemapFormBase {
$form['simple_sitemap_entities']['entities'][$entity_type_id][$entity_type_id . '_enabled'] = [ $form['simple_sitemap_entities']['entities'][$entity_type_id][$entity_type_id . '_enabled'] = [
'#type' => 'checkbox', '#type' => 'checkbox',
'#title' => $this->t('Enable @entity_type_label <em>(@entity_type_id)</em> support', ['@entity_type_label' => strtolower($entity_type_label), '@entity_type_id' => $entity_type_id]), '#title' => $this->t('Enable @entity_type_label <em>(@entity_type_id)</em> support', ['@entity_type_label' => $entity_type_label, '@entity_type_id' => $entity_type_id]),
'#description' => $atomic_entity_type '#description' => $atomic_entity_type
? $this->t('Sitemap settings for the entity type <em>@entity_type_label</em> can be set below and overridden on its entity pages.', ['@entity_type_label' => strtolower($entity_type_label)]) ? $this->t('Sitemap settings for the entity type <em>@entity_type_label</em> can be set below and overridden on its entity pages.', ['@entity_type_label' => $entity_type_label])
: $this->t('Sitemap settings for the entity type <em>@entity_type_label</em> can be set on its bundle pages and overridden on its entity pages.', ['@entity_type_label' => strtolower($entity_type_label)]), : $this->t('Sitemap settings for the entity type <em>@entity_type_label</em> can be set on its bundle pages and overridden on its entity pages.', ['@entity_type_label' => $entity_type_label]),
'#default_value' => $enabled_entity_type, '#default_value' => $enabled_entity_type,
]; ];
if ($form['simple_sitemap_entities']['entities'][$entity_type_id][$entity_type_id . '_enabled']['#default_value']) { if ($form['simple_sitemap_entities']['entities'][$entity_type_id][$entity_type_id . '_enabled']['#default_value']) {
$bundle_info = ''; $indexed_bundles_string = '';
$indexed_bundles = isset($bundle_settings[$entity_type_id]) if (isset($indexed_bundles[$entity_type_id])) {
? implode(array_keys(array_filter($bundle_settings[$entity_type_id], function ($val) {return $val['index'];})), ', ') foreach ($indexed_bundles[$entity_type_id] as $bundle => $bundle_data) {
: ''; $indexed_bundles_string .= '<br><em>' . $bundle_data['bundle_label'] . '</em> <span class="description">(' . $this->t('sitemap variants') . ': <em>' . implode($bundle_data['variants'], ', ') . '</em>)</span>';
}
}
$bundle_info = '';
if (!$atomic_entity_type) { if (!$atomic_entity_type) {
$bundle_info .= '<div id="indexed-bundles-' . $css_entity_type_id . '">' $bundle_info .= '<div id="indexed-bundles-' . $css_entity_type_id . '">'
. (!empty($indexed_bundles) . (!empty($indexed_bundles_string)
? $this->t("<em>@entity_type_label</em> bundles set to be indexed:", ['@entity_type_label' => ucfirst(strtolower($entity_type_label))]) . ' ' . '<em>' . $indexed_bundles . '</em>' ? $this->t("<em>@entity_type_label</em> bundles set to be indexed:", ['@entity_type_label' => $entity_type_label]) . ' ' . $indexed_bundles_string
: $this->t('No <em>@entity_type_label</em> bundles are set to be indexed yet.', ['@entity_type_label' => strtolower($entity_type_label)])) : $this->t('No <em>@entity_type_label</em> bundles are set to be indexed yet.', ['@entity_type_label' => $entity_type_label]))
. '</div>'; . '</div>';
} }
if (!empty($indexed_bundles)) { if (!empty($indexed_bundles_string)) {
$bundle_info .= '<div id="warning-' . $css_entity_type_id . '">' $bundle_info .= '<div id="warning-' . $css_entity_type_id . '">'
. ($atomic_entity_type . ($atomic_entity_type
? $this->t("<strong>Warning:</strong> This entity type's sitemap settings including per-entity overrides will be deleted after hitting <em>Save</em>.") ? $this->t("<strong>Warning:</strong> This entity type's sitemap settings including per-entity overrides will be deleted after hitting <em>Save</em>.")
: $this->t("<strong>Warning:</strong> The sitemap settings for <em>@bundles</em> and any per-entity overrides will be deleted after hitting <em>Save</em>.", : $this->t("<strong>Warning:</strong> The sitemap settings and any per-entity overrides will be deleted for the following bundles:" . $indexed_bundles_string))
['@bundles' => $indexed_bundles]))
. '</div>'; . '</div>';
} }
...@@ -131,18 +142,18 @@ class SimplesitemapEntitiesForm extends SimplesitemapFormBase { ...@@ -131,18 +142,18 @@ class SimplesitemapEntitiesForm extends SimplesitemapFormBase {
$form['#attached']['drupalSettings']['simple_sitemap']['all_entities'][] = $css_entity_type_id; $form['#attached']['drupalSettings']['simple_sitemap']['all_entities'][] = $css_entity_type_id;
if ($atomic_entity_type) { if ($atomic_entity_type) {
$form['simple_sitemap_entities']['entities'][$entity_type_id][$entity_type_id . '_settings']['#prefix'] = '<div id="indexed-bundles-' . $css_entity_type_id . '">';
$form['simple_sitemap_entities']['entities'][$entity_type_id][$entity_type_id . '_settings']['#suffix'] = '</div>';
$this->formHelper $this->formHelper
->cleanUpFormInfo() ->cleanUpFormInfo()
->setEntityCategory('bundle') ->setEntityCategory('bundle')
->setEntityTypeId($entity_type_id) ->setEntityTypeId($entity_type_id)
->setBundleName($entity_type_id) ->setBundleName($entity_type_id)
->negotiateVariant() ->negotiateSettings()
->displayEntitySettings( ->displayEntitySettings(
$form['simple_sitemap_entities']['entities'][$entity_type_id][$entity_type_id . '_settings'], $form['simple_sitemap_entities']['entities'][$entity_type_id][$entity_type_id . '_settings']
TRUE
); );
$form['#attached']['drupalSettings']['simple_sitemap']['atomic_entities'][] = $css_entity_type_id;
} }
} }
...@@ -162,25 +173,18 @@ class SimplesitemapEntitiesForm extends SimplesitemapFormBase { ...@@ -162,25 +173,18 @@ class SimplesitemapEntitiesForm extends SimplesitemapFormBase {
if ($value) { if ($value) {
$this->generator->enableEntityType($entity_type_id); $this->generator->enableEntityType($entity_type_id);
if ($this->entityHelper->entityTypeIsAtomic($entity_type_id)) { if ($this->entityHelper->entityTypeIsAtomic($entity_type_id)) {
foreach ($this->generator->getSitemapManager()->getSitemapVariants(NULL, FALSE) as $variant => $definition) {
// Deleting bundle settings for old bundle. if (isset($values['index_' . $variant . '_' . $entity_type_id . '_settings'])) {
// See simple_sitemap.module::simple_sitemap_entity_form_submit(). $this->generator
// todo: Not necessary once https://www.drupal.org/project/simple_sitemap/issues/3014649 is implemented. ->setVariants($variant)
if (isset($form['simple_sitemap_entities']['entities'][$entity_type_id][$entity_type_id . '_settings'][$entity_type_id . '_simple_sitemap_variant']['#default_value'])) { ->setBundleSettings($entity_type_id, $entity_type_id, [
$old_variant = $form['simple_sitemap_entities']['entities'][$entity_type_id][$entity_type_id . '_settings'][$entity_type_id . '_simple_sitemap_variant']['#default_value']; 'index' => (bool) $values['index_' . $variant . '_' . $entity_type_id . '_settings'],
if ($old_variant !== $values[$entity_type_id . '_simple_sitemap_variant']) { 'priority' => $values['priority_' . $variant . '_' . $entity_type_id . '_settings'],
$this->generator->setVariants($old_variant)->removeBundleSettings($entity_type_id); 'changefreq' => $values['changefreq_' . $variant . '_' . $entity_type_id . '_settings'],
'include_images' => (bool) $values['include_images_' . $variant . '_' . $entity_type_id . '_settings'],
]);
} }
} }
$this->generator
->setVariants($values[$entity_type_id . '_simple_sitemap_variant'])
->setBundleSettings($entity_type_id, $entity_type_id, [
'index' => TRUE,
'priority' => $values[$entity_type_id . '_simple_sitemap_priority'],
'changefreq' => $values[$entity_type_id . '_simple_sitemap_changefreq'],
'include_images' => (bool) $values[$entity_type_id . '_simple_sitemap_include_images'],
]);
} }
} }
else { else {
......
...@@ -145,7 +145,7 @@ class SimplesitemapSettingsForm extends SimplesitemapFormBase { ...@@ -145,7 +145,7 @@ class SimplesitemapSettingsForm extends SimplesitemapFormBase {
]; ];
foreach ($variants as $variant_name => $variant_definition) { foreach ($variants as $variant_name => $variant_definition) {
$row = []; $row = [];
$row['name']['data']['#markup'] = '<span title="' . $variant_name . '">' . $variant_definition['label'] . '</span>'; $row['name']['data']['#markup'] = '<span title="' . $variant_name . '">' . $this->t($variant_definition['label']) . '</span>';
if (!isset($sitemap_statuses[$variant_name])) { if (!isset($sitemap_statuses[$variant_name])) {
$row['status'] = $this->t('pending'); $row['status'] = $this->t('pending');
} }
......
...@@ -429,6 +429,8 @@ class Simplesitemap { ...@@ -429,6 +429,8 @@ class Simplesitemap {
/** /**
* Sets settings for bundle or non-bundle entity types. This is done for the * Sets settings for bundle or non-bundle entity types. This is done for the
* currently set variant. * currently set variant.
* Please note, this method takes only the first set
* variant into account. See todo.
* *
* @param $entity_type_id * @param $entity_type_id
* @param null $bundle_name * @param null $bundle_name
...@@ -508,7 +510,7 @@ class Simplesitemap { ...@@ -508,7 +510,7 @@ class Simplesitemap {
* Limit the result set to a specific bundle name. * Limit the result set to a specific bundle name.
* *
* @param bool $supplement_defaults * @param bool $supplement_defaults
* Supplements the result set with default custom link settings. * Supplements the result set with default bundle settings.
* *
* @param bool $multiple_variants * @param bool $multiple_variants
* If true, returns an array of results keyed by variant name, otherwise it * If true, returns an array of results keyed by variant name, otherwise it
...@@ -520,20 +522,18 @@ class Simplesitemap { ...@@ -520,20 +522,18 @@ class Simplesitemap {
*/ */
public function getBundleSettings($entity_type_id = NULL, $bundle_name = NULL, $supplement_defaults = TRUE, $multiple_variants = FALSE) { public function getBundleSettings($entity_type_id = NULL, $bundle_name = NULL, $supplement_defaults = TRUE, $multiple_variants = FALSE) {
$bundle_name = NULL !== $bundle_name ? $bundle_name : $entity_type_id;
$all_bundle_settings = []; $all_bundle_settings = [];
foreach ($variants = $this->getVariants(FALSE) as $variant) { foreach ($variants = $this->getVariants(FALSE) as $variant) {
if (NULL !== $entity_type_id) { if (NULL !== $entity_type_id) {
$bundle_name = NULL !== $bundle_name ? $bundle_name : $entity_type_id;
$bundle_settings = $this->configFactory $bundle_settings = $this->configFactory
->get("simple_sitemap.bundle_settings.$variant.$entity_type_id.$bundle_name") ->get("simple_sitemap.bundle_settings.$variant.$entity_type_id.$bundle_name")
->get(); ->get();
// If not found and entity type is enabled, return default bundle settings. // If not found and entity type is enabled, return default bundle settings.
if (empty($bundle_settings) && $supplement_defaults) { if (empty($bundle_settings) && $supplement_defaults) {
if ($this->entityTypeIsEnabled($entity_type_id) if (isset($this->entityTypeBundleInfo->getBundleInfo($entity_type_id)[$bundle_name])) {
&& isset($this->entityTypeBundleInfo->getBundleInfo($entity_type_id)[$bundle_name])) {
self::supplementDefaultSettings('entity', $bundle_settings); self::supplementDefaultSettings('entity', $bundle_settings);
} }
else { else {
...@@ -552,20 +552,17 @@ class Simplesitemap { ...@@ -552,20 +552,17 @@ class Simplesitemap {
// Supplement default bundle settings for all bundles not found in simple_sitemap.bundle_settings.*.* configuration. // Supplement default bundle settings for all bundles not found in simple_sitemap.bundle_settings.*.* configuration.
if ($supplement_defaults) { if ($supplement_defaults) {
foreach ($this->entityHelper->getSupportedEntityTypes() as $type_id => $type_definition) { foreach ($this->entityHelper->getSupportedEntityTypes() as $type_id => $type_definition) {
if ($this->entityTypeIsEnabled($type_id)) { foreach($this->entityTypeBundleInfo->getBundleInfo($type_id) as $bundle => $bundle_definition) {
foreach($this->entityTypeBundleInfo->getBundleInfo($type_id) as $bundle => $bundle_definition) { if (!isset($bundle_settings[$type_id][$bundle])) {
if (!isset($bundle_settings[$type_id][$bundle])) { self::supplementDefaultSettings('entity', $bundle_settings[$type_id][$bundle]);
self::supplementDefaultSettings('entity', $bundle_settings[$type_id][$bundle]);
}
} }
} }
} }
} }
} }
if ($multiple_variants) { if ($multiple_variants) {
if (!empty($bundle_settings)) { $all_bundle_settings[$variant] = $bundle_settings;
$all_bundle_settings[$variant] = $bundle_settings;
}
} }
else { else {
return $bundle_settings; return $bundle_settings;
...@@ -706,6 +703,8 @@ class Simplesitemap { ...@@ -706,6 +703,8 @@ class Simplesitemap {
* Gets sitemap settings for an entity instance which overrides bundle * Gets sitemap settings for an entity instance which overrides bundle
* settings, or gets bundle settings, if they are not overridden. This is * settings, or gets bundle settings, if they are not overridden. This is
* done for the currently set variant. * done for the currently set variant.
* Please note, this method takes only the first set
* variant into account. See todo.
* *
* @param string $entity_type_id * @param string $entity_type_id
* @param string $id * @param string $id
...@@ -781,19 +780,21 @@ class Simplesitemap { ...@@ -781,19 +780,21 @@ class Simplesitemap {
/** /**
* Checks if an entity bundle (or a non-bundle entity type) is set to be * Checks if an entity bundle (or a non-bundle entity type) is set to be
* indexed for the currently set variant. * indexed for any of the currently set variants.
* *
* @param string $entity_type_id * @param string $entity_type_id
* @param string|null $bundle_name * @param string|null $bundle_name
* *
* @return bool * @return bool
*
* @todo multiple variants
*/ */