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();
$(target).change(function() {
triggerVisibility(target, entityId);
});
});
// 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();
function triggerVisibility(target, entityId) {
if ($(target).is(':checked')) {
$('#warning-' + entityId).hide();
$('#indexed-bundles-' + entityId).show();
}
else {
$('#warning-' + value).show();
$('#indexed-bundles-' + value).hide();
$('#warning-' + entityId).show();
$('#indexed-bundles-' + entityId).hide();
}
}
// Show 'Regenerate sitemap' field if 'enabled' setting has changed.
$('.form-item-simple-sitemap-regenerate-now').show();
});
});
// 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();
// });
// });
}
};
})(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,41 +98,40 @@ 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'];
}
foreach ($generator->getSitemapManager()->getSitemapVariants(NULL, FALSE) as $variant => $definition) {
// 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());
}
}
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->setVariants($values['simple_sitemap_variant'])
->setBundleSettings($f->getEntityTypeId(),
$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->setVariants($values['simple_sitemap_variant'])
->setEntityInstanceSettings($f->getEntityTypeId(),
$generator->setEntityInstanceSettings($f->getEntityTypeId(),
!empty($f->getInstanceId()) ? $f->getInstanceId() : $f->getFormEntityId(),
$settings
);
break;
}
}
}
// Regenerate sitemaps according to user setting.
if ($values['simple_sitemap_regenerate_now']) {
......
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'];
}
/**
......
This diff is collapsed.
......@@ -70,18 +70,27 @@ class SimplesitemapEntitiesForm extends SimplesitemapFormBase {
$form['#attached']['library'][] = 'simple_sitemap/sitemapEntities';
$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 = [];
foreach ($this->entityHelper->getSupportedEntityTypes() as $entity_type_id => $entity_type) {
$entity_type_labels[$entity_type_id] = $entity_type->getLabel() ? : $entity_type_id;
}
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) {
;
$enabled_entity_type = $this->generator->entityTypeIsEnabled($entity_type_id);
$atomic_entity_type = $this->entityHelper->entityTypeIsAtomic($entity_type_id);
$css_entity_type_id = str_replace('_', '-', $entity_type_id);
......@@ -94,34 +103,36 @@ class SimplesitemapEntitiesForm extends SimplesitemapFormBase {
$form['simple_sitemap_entities']['entities'][$entity_type_id][$entity_type_id . '_enabled'] = [
'#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
? $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 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 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' => $entity_type_label]),
'#default_value' => $enabled_entity_type,
];
if ($form['simple_sitemap_entities']['entities'][$entity_type_id][$entity_type_id . '_enabled']['#default_value']) {
$bundle_info = '';
$indexed_bundles = isset($bundle_settings[$entity_type_id])
? implode(array_keys(array_filter($bundle_settings[$entity_type_id], function ($val) {return $val['index'];})), ', ')
: '';
$indexed_bundles_string = '';
if (isset($indexed_bundles[$entity_type_id])) {
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) {
$bundle_info .= '<div id="indexed-bundles-' . $css_entity_type_id . '">'
. (!empty($indexed_bundles)
? $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('No <em>@entity_type_label</em> bundles are set to be indexed yet.', ['@entity_type_label' => strtolower($entity_type_label)]))
. (!empty($indexed_bundles_string)
? $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' => $entity_type_label]))
. '</div>';
}
if (!empty($indexed_bundles)) {
if (!empty($indexed_bundles_string)) {
$bundle_info .= '<div id="warning-' . $css_entity_type_id . '">'
. ($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> The sitemap settings for <em>@bundles</em> and any per-entity overrides will be deleted after hitting <em>Save</em>.",
['@bundles' => $indexed_bundles]))
: $this->t("<strong>Warning:</strong> The sitemap settings and any per-entity overrides will be deleted for the following bundles:" . $indexed_bundles_string))
. '</div>';
}
......@@ -131,18 +142,18 @@ class SimplesitemapEntitiesForm extends SimplesitemapFormBase {
$form['#attached']['drupalSettings']['simple_sitemap']['all_entities'][] = $css_entity_type_id;
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
->cleanUpFormInfo()
->setEntityCategory('bundle')
->setEntityTypeId($entity_type_id)
->setBundleName($entity_type_id)
->negotiateVariant()
->negotiateSettings()
->displayEntitySettings(
$form['simple_sitemap_entities']['entities'][$entity_type_id][$entity_type_id . '_settings'],
TRUE
$form['simple_sitemap_entities']['entities'][$entity_type_id][$entity_type_id . '_settings']
);
$form['#attached']['drupalSettings']['simple_sitemap']['atomic_entities'][] = $css_entity_type_id;
}
}
......@@ -162,27 +173,20 @@ class SimplesitemapEntitiesForm extends SimplesitemapFormBase {
if ($value) {
$this->generator->enableEntityType($entity_type_id);
if ($this->entityHelper->entityTypeIsAtomic($entity_type_id)) {
// Deleting bundle settings for old bundle.
// See simple_sitemap.module::simple_sitemap_entity_form_submit().
// todo: Not necessary once https://www.drupal.org/project/simple_sitemap/issues/3014649 is implemented.
if (isset($form['simple_sitemap_entities']['entities'][$entity_type_id][$entity_type_id . '_settings'][$entity_type_id . '_simple_sitemap_variant']['#default_value'])) {
$old_variant = $form['simple_sitemap_entities']['entities'][$entity_type_id][$entity_type_id . '_settings'][$entity_type_id . '_simple_sitemap_variant']['#default_value'];
if ($old_variant !== $values[$entity_type_id . '_simple_sitemap_variant']) {
$this->generator->setVariants($old_variant)->removeBundleSettings($entity_type_id);
}
}
foreach ($this->generator->getSitemapManager()->getSitemapVariants(NULL, FALSE) as $variant => $definition) {
if (isset($values['index_' . $variant . '_' . $entity_type_id . '_settings'])) {
$this->generator
->setVariants($values[$entity_type_id . '_simple_sitemap_variant'])
->setVariants($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'],
'index' => (bool) $values['index_' . $variant . '_' . $entity_type_id . '_settings'],
'priority' => $values['priority_' . $variant . '_' . $entity_type_id . '_settings'],
'changefreq' => $values['changefreq_' . $variant . '_' . $entity_type_id . '_settings'],
'include_images' => (bool) $values['include_images_' . $variant . '_' . $entity_type_id . '_settings'],
]);
}
}
}
}
else {
$this->generator->disableEntityType($entity_type_id);
}
......
......@@ -145,7 +145,7 @@ class SimplesitemapSettingsForm extends SimplesitemapFormBase {
];
foreach ($variants as $variant_name => $variant_definition) {
$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])) {
$row['status'] = $this->t('pending');
}
......
......@@ -429,6 +429,8 @@ class Simplesitemap {
/**
* Sets settings for bundle or non-bundle entity types. This is done for the
* currently set variant.
* Please note, this method takes only the first set
* variant into account. See todo.
*
* @param $entity_type_id
* @param null $bundle_name
......@@ -508,7 +510,7 @@ class Simplesitemap {
* Limit the result set to a specific bundle name.
*
* @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
* If true, returns an array of results keyed by variant name, otherwise it
......@@ -520,20 +522,18 @@ class Simplesitemap {
*/
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 = [];
foreach ($variants = $this->getVariants(FALSE) as $variant) {
if (NULL !== $entity_type_id) {
$bundle_name = NULL !== $bundle_name ? $bundle_name : $entity_type_id;
$bundle_settings = $this->configFactory
->get("simple_sitemap.bundle_settings.$variant.$entity_type_id.$bundle_name")
->get();
// If not found and entity type is enabled, return default bundle settings.
if (empty($bundle_settings) && $supplement_defaults) {
if ($this->entityTypeIsEnabled($entity_type_id)
&& isset($this->entityTypeBundleInfo->getBundleInfo($entity_type_id)[$bundle_name])) {
if (isset($this->entityTypeBundleInfo->getBundleInfo($entity_type_id)[$bundle_name])) {
self::supplementDefaultSettings('entity', $bundle_settings);
}
else {
......@@ -552,7 +552,6 @@ class Simplesitemap {
// Supplement default bundle settings for all bundles not found in simple_sitemap.bundle_settings.*.* configuration.
if ($supplement_defaults) {
foreach ($this->entityHelper->getSupportedEntityTypes() as $type_id => $type_definition) {
if ($this->entityTypeIsEnabled($type_id)) {
foreach($this->entityTypeBundleInfo->getBundleInfo($type_id) as $bundle => $bundle_definition) {
if (!isset($bundle_settings[$type_id][$bundle])) {
self::supplementDefaultSettings('entity', $bundle_settings[$type_id][$bundle]);
......@@ -561,12 +560,10 @@ class Simplesitemap {
}
}
}
}
if ($multiple_variants) {
if (!empty($bundle_settings)) {
$all_bundle_settings[$variant] = $bundle_settings;
}
}
else {
return $bundle_settings;
}
......@@ -706,6 +703,8 @@ class Simplesitemap {
* Gets sitemap settings for an entity instance which overrides bundle
* settings, or gets bundle settings, if they are not overridden. This is
* 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 $id
......@@ -781,19 +780,21 @@ class Simplesitemap {
/**
* 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|null $bundle_name
*
* @return bool
*
* @todo multiple variants
*/
public function bundleIsIndexed($entity_type_id, $bundle_name = NULL) {
$settings = $this->getBundleSettings($entity_type_id, $bundle_name);
foreach ($this->getBundleSettings($entity_type_id, $bundle_name, FALSE, TRUE) as $settings) {
if (!empty($settings['index'])) {
return TRUE;
}
}
return !empty($settings['index']);
return FALSE;
}
/**
......
......@@ -96,15 +96,14 @@ class SimplesitemapTest extends SimplesitemapTestBase {
$this->drupalGet($this->defaultSitemapUrl);
$this->assertSession()->responseNotContains('node/' . $this->node->id());
//todo Not working
// // Test removing all custom paths from the sitemap.
// $this->generator->removeCustomLinks()
// ->generateSitemap('backend');
//
// $this->drupalGet($this->defaultSitemapUrl);
// $this->assertSession()->responseNotContains(
// Url::fromRoute('<front>')->setAbsolute()->toString()
// );
// Test removing all custom paths from the sitemap.
$this->generator->removeCustomLinks()
->generateSitemap('backend');
$this->drupalGet($this->defaultSitemapUrl);
$this->assertSession()->responseNotContains(
Url::fromRoute('<front>')->setAbsolute()->toString()
);
}
/**
......@@ -176,17 +175,16 @@ class SimplesitemapTest extends SimplesitemapTestBase {
$this->assertSession()->responseContains('node/' . $this->node->id());
$this->assertSession()->responseContains('node/' . $node3->id());
// todo Now working
// // Set bundle 'index' setting to false.
// $this->generator
// ->setBundleSettings('node', 'page', ['index' => FALSE])
// ->setBundleSettings('node', 'blog', ['index' => FALSE])
// ->generateSitemap('backend');
//
// $this->drupalGet($this->defaultSitemapUrl);
//
// $this->assertSession()->responseNotContains('node/' . $this->node->id());
// $this->assertSession()->responseNotContains('node/' . $node3->id());
// Set bundle 'index' setting to false.
$this->generator
->setBundleSettings('node', 'page', ['index' => FALSE])
->setBundleSettings('node', 'blog', ['index' => FALSE])
->generateSitemap('backend');
$this->drupalGet($this->defaultSitemapUrl);
$this->assertSession()->responseNotContains('node/' . $this->node->id());
$this->assertSession()->responseNotContains('node/' . $node3->id());
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment