diff --git a/composer.json b/composer.json index ac03753767b1af33f95d056cd28a8e7e2a35d42c..631ea6f78bca10f88927e13ab806eb33576400d3 100644 --- a/composer.json +++ b/composer.json @@ -152,7 +152,7 @@ "drupal/roleassign": "2.0.0", "drupal/scheduler": "1.5", "drupal/simple_gmap": "3.1.0", - "drupal/simple_sitemap": "4.1.6", + "drupal/simple_sitemap": "4.1.7", "drupal/smtp": "1.2", "drupal/social_media": "2.0.0", "drupal/social_media_links": "^2.8", diff --git a/composer.lock b/composer.lock index 372dffe7c717ac9902bfb0fa6d736c67d445e940..423b51d608bacde8f69d39d54a7e00a84fd58c06 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "2a02d0e2e8242ba7416066e2ff6e0150", + "content-hash": "25972081893ee7c1cfb1605764858109", "packages": [ { "name": "asm89/stack-cors", @@ -5897,17 +5897,17 @@ }, { "name": "drupal/simple_sitemap", - "version": "4.1.6", + "version": "4.1.7", "source": { "type": "git", "url": "https://git.drupalcode.org/project/simple_sitemap.git", - "reference": "4.1.6" + "reference": "4.1.7" }, "dist": { "type": "zip", - "url": "https://ftp.drupal.org/files/projects/simple_sitemap-4.1.6.zip", - "reference": "4.1.6", - "shasum": "5ea5ee97ab4d59b43db86dd6279c3ac5ecbe69b9" + "url": "https://ftp.drupal.org/files/projects/simple_sitemap-4.1.7.zip", + "reference": "4.1.7", + "shasum": "3d55ee386b0ebb81ed4c3461451a9e32a15d93d7" }, "require": { "drupal/core": "^9.3 || ^10", @@ -5916,8 +5916,8 @@ "type": "drupal-module", "extra": { "drupal": { - "version": "4.1.6", - "datestamp": "1686288643", + "version": "4.1.7", + "datestamp": "1698936269", "security-coverage": { "status": "covered", "message": "Covered by Drupal's security advisory policy" diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 610b100d50501a113f8070c27ea5db958f60fdf4..9aec5573266dbec3ebf9acaf0396daaee49bf08a 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -6171,18 +6171,18 @@ }, { "name": "drupal/simple_sitemap", - "version": "4.1.6", - "version_normalized": "4.1.6.0", + "version": "4.1.7", + "version_normalized": "4.1.7.0", "source": { "type": "git", "url": "https://git.drupalcode.org/project/simple_sitemap.git", - "reference": "4.1.6" + "reference": "4.1.7" }, "dist": { "type": "zip", - "url": "https://ftp.drupal.org/files/projects/simple_sitemap-4.1.6.zip", - "reference": "4.1.6", - "shasum": "5ea5ee97ab4d59b43db86dd6279c3ac5ecbe69b9" + "url": "https://ftp.drupal.org/files/projects/simple_sitemap-4.1.7.zip", + "reference": "4.1.7", + "shasum": "3d55ee386b0ebb81ed4c3461451a9e32a15d93d7" }, "require": { "drupal/core": "^9.3 || ^10", @@ -6191,8 +6191,8 @@ "type": "drupal-module", "extra": { "drupal": { - "version": "4.1.6", - "datestamp": "1686288643", + "version": "4.1.7", + "datestamp": "1698936269", "security-coverage": { "status": "covered", "message": "Covered by Drupal's security advisory policy" diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index ce3011d089f1e05ae7f82ac5b887397336a5b463..deac41d61eee3f0cfb498df15d165f297d2389a0 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -3,7 +3,7 @@ 'name' => 'osu-asc-webservices/d8-upstream', 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => '6d88cd620aad5c039922728fc2c186268a052911', + 'reference' => '984a7e9818b3dc912897bc31a7bf7e0ca9897d1b', 'type' => 'project', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), @@ -1007,9 +1007,9 @@ 'dev_requirement' => false, ), 'drupal/simple_sitemap' => array( - 'pretty_version' => '4.1.6', - 'version' => '4.1.6.0', - 'reference' => '4.1.6', + 'pretty_version' => '4.1.7', + 'version' => '4.1.7.0', + 'reference' => '4.1.7', 'type' => 'drupal-module', 'install_path' => __DIR__ . '/../../web/modules/simple_sitemap', 'aliases' => array(), @@ -1393,7 +1393,7 @@ 'osu-asc-webservices/d8-upstream' => array( 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => '6d88cd620aad5c039922728fc2c186268a052911', + 'reference' => '984a7e9818b3dc912897bc31a7bf7e0ca9897d1b', 'type' => 'project', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), diff --git a/web/modules/simple_sitemap/README.md b/web/modules/simple_sitemap/README.md index f087a272a2f9fe599dd3dfa88ecdbd9548026598..c8a15265f83373e6d6134490243716cf9b2a30b7 100644 --- a/web/modules/simple_sitemap/README.md +++ b/web/modules/simple_sitemap/README.md @@ -208,7 +208,9 @@ to generation: There are API methods for altering stored inclusion settings, status queries and programmatic sitemap generation. These include: * simple_sitemap.generator - * setVariants + * setSitemaps + * getSitemaps + * getDefaultSitemap * getSetting * saveSetting * getContent @@ -216,6 +218,8 @@ programmatic sitemap generation. These include: * queue * rebuildQueue * entityManager + * setSitemaps + * getSitemaps * enableEntityType * disableEntityType * setBundleSettings @@ -228,6 +232,8 @@ programmatic sitemap generation. These include: * bundleIsIndexed * entityTypeIsEnabled * customLinkManager + * setSitemaps + * getSitemaps * add * get * remove diff --git a/web/modules/simple_sitemap/js/simple_sitemap.sitemapEntities.js b/web/modules/simple_sitemap/js/simple_sitemap.sitemapEntities.js index 3b5a1a78f1290fa5e848d810f4f820120afa9adf..ce7ba3497a379289768796cd5c42fb024b9fed4d 100644 --- a/web/modules/simple_sitemap/js/simple_sitemap.sitemapEntities.js +++ b/web/modules/simple_sitemap/js/simple_sitemap.sitemapEntities.js @@ -2,13 +2,13 @@ * @file * Attaches simple_sitemap behaviors to the sitemap entities form. */ -(function ($, Drupal) { +(function ($, Drupal, once) { "use strict"; Drupal.behaviors.simpleSitemapEntities = { attach: function () { - let $checkboxes = $('table tr input:checkbox:checked').once('simple-sitemap-entities'); + let $checkboxes = $(once('simple-sitemap-entities', 'table tr input[type=checkbox][checked]')); if ($checkboxes.length) { $checkboxes.on('change', function () { @@ -37,4 +37,4 @@ } }); -})(jQuery, Drupal); +})(jQuery, Drupal, once); diff --git a/web/modules/simple_sitemap/modules/simple_sitemap_engines/simple_sitemap_engines.info.yml b/web/modules/simple_sitemap/modules/simple_sitemap_engines/simple_sitemap_engines.info.yml index 284c155361b79ba046a708b9ee22744a897a5f21..da7524876890df44d1a39d9b89f9ea447303da56 100644 --- a/web/modules/simple_sitemap/modules/simple_sitemap_engines/simple_sitemap_engines.info.yml +++ b/web/modules/simple_sitemap/modules/simple_sitemap_engines/simple_sitemap_engines.info.yml @@ -7,7 +7,7 @@ core_version_requirement: ^9.3 || ^10 dependencies: - simple_sitemap:simple_sitemap -# Information added by Drupal.org packaging script on 2023-06-09 -version: '4.1.6' +# Information added by Drupal.org packaging script on 2023-11-02 +version: '4.1.7' project: 'simple_sitemap' -datestamp: 1686288645 +datestamp: 1698936272 diff --git a/web/modules/simple_sitemap/modules/simple_sitemap_engines/simple_sitemap_engines.install b/web/modules/simple_sitemap/modules/simple_sitemap_engines/simple_sitemap_engines.install index 6c021d98b56438dbe651125e90758353ee50d582..2e768888ccb7fc05402578bd3ef3259aea70db62 100644 --- a/web/modules/simple_sitemap/modules/simple_sitemap_engines/simple_sitemap_engines.install +++ b/web/modules/simple_sitemap/modules/simple_sitemap_engines/simple_sitemap_engines.install @@ -120,7 +120,7 @@ function simple_sitemap_engines_update_8402() { $entity_manager = \Drupal::service('simple_sitemap.entity_manager'); $all_bundle_settings = $entity_manager - ->setVariants($default_variant) + ->setSitemaps($default_variant) ->getAllBundleSettings(); if (!empty($all_bundle_settings[$default_variant])) { foreach ($all_bundle_settings[$default_variant] as $entity_type_name => $bundle_settings) { diff --git a/web/modules/simple_sitemap/modules/simple_sitemap_engines/src/Form/SimplesitemapEnginesForm.php b/web/modules/simple_sitemap/modules/simple_sitemap_engines/src/Form/SimplesitemapEnginesForm.php index 8f2733a388e32186d3fa281c9c9f794e1349c355..2255bc7fa7215f0da784310f4ba9e76371123d2f 100644 --- a/web/modules/simple_sitemap/modules/simple_sitemap_engines/src/Form/SimplesitemapEnginesForm.php +++ b/web/modules/simple_sitemap/modules/simple_sitemap_engines/src/Form/SimplesitemapEnginesForm.php @@ -137,10 +137,10 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#type' => 'details', '#title' => $this->t('Engines'), '#markup' => '<div class="description">' - . $this->t('Choose which sitemaps are to be submitted to which search engines.<br>Sitemaps can be configured <a href="@url">here</a>.', + . $this->t('Choose which sitemaps are to be submitted to which search engines.<br>Sitemaps can be configured <a href="@url">here</a>.', ['@url' => Url::fromRoute('entity.simple_sitemap.collection')->toString()] - ) - . '</div>', + ) + . '</div>', '#open' => TRUE, '#states' => [ 'visible' => [':input[name="settings[enabled]"]' => ['checked' => TRUE]], diff --git a/web/modules/simple_sitemap/modules/simple_sitemap_views/js/simple_sitemap.viewsUi.js b/web/modules/simple_sitemap/modules/simple_sitemap_views/js/simple_sitemap.viewsUi.js index 393df1a5a3081f660912b2380319a3b098d7332c..f2b9c30ba20c932d44bea4ac5af17c2804adfe69 100755 --- a/web/modules/simple_sitemap/modules/simple_sitemap_views/js/simple_sitemap.viewsUi.js +++ b/web/modules/simple_sitemap/modules/simple_sitemap_views/js/simple_sitemap.viewsUi.js @@ -3,12 +3,12 @@ * Views UI helpers for Simple XML Sitemap display extender. */ -(function ($, Drupal) { +(function ($, Drupal, once) { Drupal.simpleSitemapViewsUi = {}; Drupal.behaviors.simpleSitemapViewsUiArguments = { attach: function attach() { - let $arguments = $('.indexed-arguments').once('simple-sitemap-views-ui-arguments'); + let $arguments = $(once('simple-sitemap-views-ui-arguments', '.indexed-arguments')); if ($arguments.length) { $arguments.each(function () { @@ -40,4 +40,4 @@ this.$checkboxes.slice(index).prop('checked', false); }; -})(jQuery, Drupal); +})(jQuery, Drupal, once); diff --git a/web/modules/simple_sitemap/modules/simple_sitemap_views/simple_sitemap_views.info.yml b/web/modules/simple_sitemap/modules/simple_sitemap_views/simple_sitemap_views.info.yml index 78ef0bedd2656eb6653cd51f0aee6a0fd5b9a1a7..789c2771544ab3be361002979f71afc186110f31 100644 --- a/web/modules/simple_sitemap/modules/simple_sitemap_views/simple_sitemap_views.info.yml +++ b/web/modules/simple_sitemap/modules/simple_sitemap_views/simple_sitemap_views.info.yml @@ -8,7 +8,7 @@ dependencies: - simple_sitemap:simple_sitemap - drupal:views -# Information added by Drupal.org packaging script on 2023-06-09 -version: '4.1.6' +# Information added by Drupal.org packaging script on 2023-11-02 +version: '4.1.7' project: 'simple_sitemap' -datestamp: 1686288645 +datestamp: 1698936272 diff --git a/web/modules/simple_sitemap/modules/simple_sitemap_views/src/SimpleSitemapViews.php b/web/modules/simple_sitemap/modules/simple_sitemap_views/src/SimpleSitemapViews.php index efd028decb90b9cda1df29e8dff4170ce8c8a3e7..6acecb4aa5019cfa05d00d8243771a320f097d67 100755 --- a/web/modules/simple_sitemap/modules/simple_sitemap_views/src/SimpleSitemapViews.php +++ b/web/modules/simple_sitemap/modules/simple_sitemap_views/src/SimpleSitemapViews.php @@ -16,6 +16,9 @@ /** * Class to manage sitemap data for views. + * + * @todo Replace with something similar to CustomLinkManager including + * getting/setting of sitemaps. */ class SimpleSitemapViews { diff --git a/web/modules/simple_sitemap/modules/simple_sitemap_views/tests/modules/simple_sitemap_views_test/simple_sitemap_views_test.info.yml b/web/modules/simple_sitemap/modules/simple_sitemap_views/tests/modules/simple_sitemap_views_test/simple_sitemap_views_test.info.yml index 837cd2a3e45d359c6bef662b167a6113072af61d..4f2d43d67d07a408f2b2f654f86f72e46645a711 100644 --- a/web/modules/simple_sitemap/modules/simple_sitemap_views/tests/modules/simple_sitemap_views_test/simple_sitemap_views_test.info.yml +++ b/web/modules/simple_sitemap/modules/simple_sitemap_views/tests/modules/simple_sitemap_views_test/simple_sitemap_views_test.info.yml @@ -5,7 +5,7 @@ package: Testing dependencies: - simple_sitemap:simple_sitemap_views -# Information added by Drupal.org packaging script on 2023-06-09 -version: '4.1.6' +# Information added by Drupal.org packaging script on 2023-11-02 +version: '4.1.7' project: 'simple_sitemap' -datestamp: 1686288645 +datestamp: 1698936272 diff --git a/web/modules/simple_sitemap/modules/simple_sitemap_views/tests/src/Functional/SimpleSitemapViewsTest.php b/web/modules/simple_sitemap/modules/simple_sitemap_views/tests/src/Functional/SimpleSitemapViewsTest.php index b06048bc222aec17e21e42e2ff0487eb69ae277f..457634f912b44358738d1a030195ce5d04a09a3a 100644 --- a/web/modules/simple_sitemap/modules/simple_sitemap_views/tests/src/Functional/SimpleSitemapViewsTest.php +++ b/web/modules/simple_sitemap/modules/simple_sitemap_views/tests/src/Functional/SimpleSitemapViewsTest.php @@ -3,6 +3,7 @@ namespace Drupal\Tests\simple_sitemap_views\Functional; use Drupal\simple_sitemap\Entity\SimpleSitemapType; +use Drupal\simple_sitemap\Queue\QueueWorker; /** * Tests Simple XML Sitemap (Views) functional integration. @@ -100,7 +101,7 @@ public function testViewsUrlGenerator() { $this->sitemapViews->addArgumentsToIndex($this->testView, ['page']); $this->sitemapViews->addArgumentsToIndex($this->testView, ['page', $title]); $this->sitemapViews->addArgumentsToIndex($this->testView2, ['page', 1]); - $this->generator->generate('backend'); + $this->generator->generate(QueueWorker::GENERATE_TYPE_BACKEND); $url1 = $this->testView->getUrl()->toString(); $url2 = $this->testView->getUrl(['page', NULL, NULL])->toString(); @@ -168,7 +169,7 @@ public function testGarbageCollector() { $this->assertIndexSize(2); // Records about pages with empty result must be removed during generation. - $this->generator->generate('backend'); + $this->generator->generate(QueueWorker::GENERATE_TYPE_BACKEND); $this->assertIndexSize(0); } diff --git a/web/modules/simple_sitemap/phpcs.xml b/web/modules/simple_sitemap/phpcs.xml index f576f0c4586b2b53e0eab5b0d71b3552346d5a8f..5f893ab5e55af50d3805895209056073f06c0452 100644 --- a/web/modules/simple_sitemap/phpcs.xml +++ b/web/modules/simple_sitemap/phpcs.xml @@ -5,11 +5,11 @@ <config name="drupal_core_version" value="8"/> <file>.</file> - <rule ref="Drupal"/> - <rule ref="DrupalPractice"> - <!-- unserialize() is already used in many places. --> - <exclude name="DrupalPractice.FunctionCalls.InsecureUnserialize"/> + <rule ref="Drupal"> + <!-- Present in many places, ignore for now. --> + <exclude name="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses"/> </rule> + <rule ref="DrupalPractice"/> <!-- Update hooks may have long descriptions. --> <rule ref="Drupal.Files.LineLength.TooLong"> <exclude-pattern>\.install</exclude-pattern> diff --git a/web/modules/simple_sitemap/simple_sitemap.drush.inc b/web/modules/simple_sitemap/simple_sitemap.drush.inc index 24e9979d41c4f9c642ab4ee4a8a772ffb62f6d07..f8ea42e2235bd4a98cd08c0b648dc7d21104bfb2 100644 --- a/web/modules/simple_sitemap/simple_sitemap.drush.inc +++ b/web/modules/simple_sitemap/simple_sitemap.drush.inc @@ -3,6 +3,8 @@ /** * @file * Drush (< 9) integration. + * + * @todo Remove integration as Drush < 9 is not supported anymore. */ use Drupal\simple_sitemap\Queue\QueueWorker; diff --git a/web/modules/simple_sitemap/simple_sitemap.info.yml b/web/modules/simple_sitemap/simple_sitemap.info.yml index d67d04c7f944f46c6a87e4bec229f4006f9fb247..23ec89a8ee67c2a2735adfe726a369367b7fad99 100644 --- a/web/modules/simple_sitemap/simple_sitemap.info.yml +++ b/web/modules/simple_sitemap/simple_sitemap.info.yml @@ -5,7 +5,7 @@ configure: entity.simple_sitemap.collection package: SEO core_version_requirement: ^9.3 || ^10 -# Information added by Drupal.org packaging script on 2023-06-09 -version: '4.1.6' +# Information added by Drupal.org packaging script on 2023-11-02 +version: '4.1.7' project: 'simple_sitemap' -datestamp: 1686288645 +datestamp: 1698936272 diff --git a/web/modules/simple_sitemap/simple_sitemap.install b/web/modules/simple_sitemap/simple_sitemap.install index b23c1a1f5625759c39e55860e1d663beb585db28..d7c12fcb2b072849452d125474aa5ace3d5fb826 100644 --- a/web/modules/simple_sitemap/simple_sitemap.install +++ b/web/modules/simple_sitemap/simple_sitemap.install @@ -5,8 +5,8 @@ * Module install and update procedures. */ -use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Database\Database; +use Drupal\Core\Entity\EntityTypeInterface; use Drupal\simple_sitemap\Entity\SimpleSitemap; /** @@ -418,7 +418,7 @@ function simple_sitemap_update_8208() { ->execute()->fetchAll(\PDO::FETCH_OBJ); foreach ($results as $row) { - $settings = unserialize($row->inclusion_settings); + $settings = unserialize($row->inclusion_settings, ['allowed_classes' => FALSE]); if (!isset($settings['changefreq'])) { \Drupal::database()->update('simple_sitemap_entity_overrides') ->fields(['inclusion_settings' => serialize($settings + ['changefreq' => ''])]) @@ -454,7 +454,7 @@ function simple_sitemap_update_8209() { ->execute()->fetchAll(\PDO::FETCH_OBJ); foreach ($results as $row) { - $settings = unserialize($row->inclusion_settings); + $settings = unserialize($row->inclusion_settings, ['allowed_classes' => FALSE]); if (!isset($settings['include_images'])) { \Drupal::database()->update('simple_sitemap_entity_overrides') ->fields(['inclusion_settings' => serialize($settings + ['include_images' => 0])]) @@ -557,7 +557,7 @@ function simple_sitemap_update_8212() { ->execute()->fetchAll(\PDO::FETCH_OBJ); foreach ($results as $row) { - $settings = unserialize($row->inclusion_settings); + $settings = unserialize($row->inclusion_settings, ['allowed_classes' => FALSE]); if (isset($settings['index'])) { $settings['index'] = (bool) $settings['index']; @@ -926,3 +926,12 @@ function simple_sitemap_update_8406() { return t('A sitemap index which lists all other sitemaps is now available and can be enabled.'); } + +/** + * Delete the sitemap queue. + */ +function simple_sitemap_update_8407() { + \Drupal::service('simple_sitemap.queue_worker')->deleteQueue(); + + return t('The sitemaps need to be regenerated.'); +} diff --git a/web/modules/simple_sitemap/simple_sitemap.module b/web/modules/simple_sitemap/simple_sitemap.module index a10b620cd68609029303bf5685ed415db80915b7..203b82a162ab2cbc709fbdbc7440fdc838bf0125 100644 --- a/web/modules/simple_sitemap/simple_sitemap.module +++ b/web/modules/simple_sitemap/simple_sitemap.module @@ -106,7 +106,7 @@ function simple_sitemap_entity_delete(EntityInterface $entity) { /** @var \Drupal\simple_sitemap\Manager\Generator $generator */ $generator = \Drupal::service('simple_sitemap.generator'); - $generator->setVariants()->entityManager()->removeEntityInstanceSettings( + $generator->entityManager()->setSitemaps()->removeEntityInstanceSettings( $entity->getEntityTypeId(), $entity->id() ); } @@ -124,7 +124,7 @@ function simple_sitemap_entity_bundle_delete($entity_type_id, $bundle) { /** @var \Drupal\simple_sitemap\Manager\Generator $generator */ $generator = \Drupal::service('simple_sitemap.generator'); - $generator->setVariants()->entityManager()->removeBundleSettings($entity_type_id, $bundle); + $generator->entityManager()->setSitemaps()->removeBundleSettings($entity_type_id, $bundle); } /** @@ -139,7 +139,7 @@ function simple_sitemap_menu_delete(MenuInterface $menu) { /** @var \Drupal\simple_sitemap\Manager\Generator $generator */ $generator = \Drupal::service('simple_sitemap.generator'); - $generator->setVariants()->entityManager()->removeBundleSettings('menu_link_content', $menu->id()); + $generator->entityManager()->setSitemaps()->removeBundleSettings('menu_link_content', $menu->id()); } /** diff --git a/web/modules/simple_sitemap/src/Commands/SimpleSitemapCommands.php b/web/modules/simple_sitemap/src/Commands/SimpleSitemapCommands.php index 241a343db4b481f93297e698ce876ea35f7eb4fb..ede6b6a2918812dcf8bf073a975328d37193bac2 100644 --- a/web/modules/simple_sitemap/src/Commands/SimpleSitemapCommands.php +++ b/web/modules/simple_sitemap/src/Commands/SimpleSitemapCommands.php @@ -70,22 +70,27 @@ public function generate(): void { * @throws \Drupal\Component\Plugin\Exception\PluginException */ public function rebuildQueue(array $options = ['variants' => '']): void { - // @todo No need to load all sitemaps here. $variants = array_keys(SimpleSitemap::loadMultiple()); if (isset($options['variants']) && (string) $options['variants'] !== '') { $chosen_variants = array_map('trim', array_filter(explode(',', (string) $options['variants']))); if (!empty($erroneous_variants = array_diff($chosen_variants, $variants))) { - $message = 'The following variants do not exist: ' . implode(', ', $erroneous_variants) - . '. Available variants are: ' . implode(', ', $variants) . '.'; + $message = 'The following sitemaps do not exist: ' . implode(', ', $erroneous_variants) . '.' + . ($variants + ? (' Available variants are: ' . implode(', ', $variants)) + : '') + . '.'; $this->logger()->log('error', $message); return; } $variants = $chosen_variants; } - $this->generator->setVariants($variants)->rebuildQueue(); + $this->generator->setSitemaps($variants)->rebuildQueue(); - $this->logger()->log('notice', 'The following variants have been queued for regeneration: ' . implode(', ', $variants) . '.'); + $message = $variants + ? 'The following sitemaps have been queued for regeneration: ' . implode(', ', $variants) . '.' + : 'No sitemaps have been queued for regeneration.'; + $this->logger()->log('notice', $message); } } diff --git a/web/modules/simple_sitemap/src/Controller/SimpleSitemapController.php b/web/modules/simple_sitemap/src/Controller/SimpleSitemapController.php index 418c26c8c3a3b97362c984f965d51fd646cd75ba..2d91d8671ea8102996be2a9147b22b37ee1262a2 100644 --- a/web/modules/simple_sitemap/src/Controller/SimpleSitemapController.php +++ b/web/modules/simple_sitemap/src/Controller/SimpleSitemapController.php @@ -57,9 +57,9 @@ public static function create(ContainerInterface $container): SimpleSitemapContr * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException */ public function getSitemap(Request $request, ?string $variant = NULL): Response { - $variant = $variant ?? $this->generator->getDefaultVariant(); + $variant = $variant ?? $this->generator->getDefaultSitemap()?->id(); $page = $request->query->get('page') ? (int) $request->query->get('page') : NULL; - $output = $this->generator->setVariants($variant)->getContent($page); + $output = $this->generator->setSitemaps($variant)->getContent($page); if ($output === NULL) { throw new NotFoundHttpException(); } diff --git a/web/modules/simple_sitemap/src/Entity/SimpleSitemap.php b/web/modules/simple_sitemap/src/Entity/SimpleSitemap.php index 8b3ed7bb9e404cbc0264c63da99dc2238194ec4e..aa839a36a1ccb1c3e605a3c1eb04584401647362 100644 --- a/web/modules/simple_sitemap/src/Entity/SimpleSitemap.php +++ b/web/modules/simple_sitemap/src/Entity/SimpleSitemap.php @@ -294,7 +294,10 @@ public function toUrl($rel = 'canonical', array $options = []) { $options['base_url'] = $settings->get('base_url') ?: $GLOBALS['base_url']; } - $options['language'] = $this->languageManager()->getLanguage(LanguageInterface::LANGCODE_NOT_APPLICABLE); + // Instead of setting the $options['language'] to LanguageInterface::LANGCODE_NOT_APPLICABLE, we disable path + // processing because of a core change introduced in https://www.drupal.org/project/drupal/issues/2883450. + // See https://www.drupal.org/project/simple_sitemap/issues/3369919. + $options['path_processing'] = FALSE; return $this->isDefault() ? Url::fromRoute( diff --git a/web/modules/simple_sitemap/src/Form/CustomLinksForm.php b/web/modules/simple_sitemap/src/Form/CustomLinksForm.php index ed783eced42093ab0441bb06fa5da93029ad7b5e..e994aa8ec8fc54e33871a3d5b9c3b68cfb044735 100644 --- a/web/modules/simple_sitemap/src/Form/CustomLinksForm.php +++ b/web/modules/simple_sitemap/src/Form/CustomLinksForm.php @@ -3,7 +3,6 @@ namespace Drupal\simple_sitemap\Form; use Drupal\Core\Config\ConfigFactoryInterface; -use Drupal\simple_sitemap\Entity\SimpleSitemap; use Drupal\simple_sitemap\Settings; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\Form\FormStateInterface; @@ -78,8 +77,9 @@ public function getFormId(): string { public function buildForm(array $form, FormStateInterface $form_state) { $form['variants']['#tree'] = TRUE; - foreach ($this->getCustomLinkCapableSitemaps() as $variant => $sitemap) { - $custom_link_settings = $this->generator->setVariants($variant)->customLinkManager()->get(); + $custom_link_manager = $this->generator->customLinkManager(); + foreach ($custom_link_manager->getSitemaps() as $variant => $sitemap) { + $custom_link_settings = $custom_link_manager->setSitemaps($sitemap)->get(); $count = $custom_link_settings ? count($custom_link_settings[$variant]) : 0; $form['variants'][$sitemap->id()] = [ @@ -111,7 +111,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { - $sitemaps = $this->getCustomLinkCapableSitemaps(); + $sitemaps = $this->generator->customLinkManager()->getSitemaps(); foreach ($form_state->getValue('variants') as $variant => $values) { foreach ($this->stringToCustomLinks($values['custom_links']) as $i => $link_config) { $placeholders = [ @@ -153,8 +153,9 @@ public function validateForm(array &$form, FormStateInterface $form_state) { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { + $custom_link_manager = $this->generator->customLinkManager(); foreach ($form_state->getValue('variants') as $variant => $values) { - $this->generator->setVariants($variant)->customLinkManager()->remove(); + $custom_link_manager->setSitemaps($variant)->remove(); foreach ($this->stringToCustomLinks($values['custom_links']) as $link_config) { $this->generator->customLinkManager()->add($link_config['path'], $link_config); } @@ -164,23 +165,6 @@ public function submitForm(array &$form, FormStateInterface $form_state) { parent::submitForm($form, $form_state); } - /** - * Gets sitemaps that are of a type that implements a custom URL generator. - * - * @return \Drupal\simple_sitemap\Entity\SimpleSitemap[] - * Array of sitemaps of a type that implements a custom URL generator. - */ - protected function getCustomLinkCapableSitemaps(): array { - $sitemaps = SimpleSitemap::loadMultiple(); - foreach ($sitemaps as $variant => $sitemap) { - if (!$sitemap->getType()->hasUrlGenerator('custom')) { - unset($sitemaps[$variant]); - } - } - - return $sitemaps; - } - /** * Converts a string with custom links to an array. * diff --git a/web/modules/simple_sitemap/src/Form/EntitiesForm.php b/web/modules/simple_sitemap/src/Form/EntitiesForm.php index f151da8fa3568eacf2211ef8273469297a3260d4..1c0c0d1b3a88686b892deebcccefc6ecb102cb80 100644 --- a/web/modules/simple_sitemap/src/Form/EntitiesForm.php +++ b/web/modules/simple_sitemap/src/Form/EntitiesForm.php @@ -186,7 +186,7 @@ protected function getIndexedBundles(): array { if ($indexed_bundles === NULL) { $indexed_bundles = []; - foreach ($this->entityManager->setVariants()->getAllBundleSettings() as $variant => $entity_types) { + foreach ($this->entityManager->setSitemaps()->getAllBundleSettings() as $variant => $entity_types) { $sitemap_label = SimpleSitemap::load($variant)->label(); foreach ($entity_types as $entity_type_id => $bundles) { diff --git a/web/modules/simple_sitemap/src/Form/EntityBundlesForm.php b/web/modules/simple_sitemap/src/Form/EntityBundlesForm.php index c2d86f4c88fd97ee73a3ba5b21ac459a273f6dad..7b10f13fb5de69ca4f4c2d619bd3136fb2e83802 100644 --- a/web/modules/simple_sitemap/src/Form/EntityBundlesForm.php +++ b/web/modules/simple_sitemap/src/Form/EntityBundlesForm.php @@ -9,7 +9,6 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\simple_sitemap\Manager\EntityManager; use Drupal\simple_sitemap\Manager\Generator; -use Drupal\simple_sitemap\Entity\SimpleSitemap; use Drupal\simple_sitemap\Entity\EntityHelper; use Drupal\simple_sitemap\Settings; @@ -155,9 +154,8 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $entity_type_id = $form_state->getValue('entity_type_id'); $bundles = $form_state->getValue('bundles'); - // @todo No need to load all sitemaps here. - foreach (SimpleSitemap::loadMultiple() as $variant => $sitemap) { - $this->entityManager->setVariants($variant); + foreach ($this->entityManager->getSitemaps() as $variant => $sitemap) { + $this->entityManager->setSitemaps($sitemap); foreach ($bundles as $bundle_name => $settings) { if (isset($settings[$variant])) { diff --git a/web/modules/simple_sitemap/src/Form/FormHelper.php b/web/modules/simple_sitemap/src/Form/FormHelper.php index f81474763d56de0a3f7c5b1fce7dd8ff96af01b6..02111b52f49009d11b94b908c0a75ab27110f26b 100644 --- a/web/modules/simple_sitemap/src/Form/FormHelper.php +++ b/web/modules/simple_sitemap/src/Form/FormHelper.php @@ -254,7 +254,7 @@ public function regenerateNowForm(array $form): array { */ public function regenerateNowFormSubmit(array &$form, FormStateInterface $form_state) { if ($form_state->getValue('simple_sitemap_regenerate_now')) { - $this->generator->setVariants()->rebuildQueue()->generate(); + $this->generator->setSitemaps()->rebuildQueue()->generate(); } } diff --git a/web/modules/simple_sitemap/src/Form/Handler/BundleEntityFormHandler.php b/web/modules/simple_sitemap/src/Form/Handler/BundleEntityFormHandler.php index c7ab9367f0055a02a853823651f437b9528d5388..0c68f075614a4b8ca76a562d7a9ed7fe5f216cf3 100644 --- a/web/modules/simple_sitemap/src/Form/Handler/BundleEntityFormHandler.php +++ b/web/modules/simple_sitemap/src/Form/Handler/BundleEntityFormHandler.php @@ -3,7 +3,6 @@ namespace Drupal\simple_sitemap\Form\Handler; use Drupal\Core\Form\FormStateInterface; -use Drupal\simple_sitemap\Entity\SimpleSitemap; /** * Defines the handler for bundle entity forms. @@ -23,7 +22,7 @@ public function settingsForm(array $form): array { ->getBundleLabel($this->entityTypeId, $this->bundleName); } - foreach (SimpleSitemap::loadMultiple() as $variant => $sitemap) { + foreach ($this->generator->entityManager()->getSitemaps() as $variant => $sitemap) { $variant_form = &$form[$variant]; if (isset($bundle_label)) { @@ -52,15 +51,14 @@ public function settingsForm(array $form): array { public function submitForm(array &$form, FormStateInterface $form_state) { parent::submitForm($form, $form_state); - // @todo No need to load all sitemaps here. - foreach (SimpleSitemap::loadMultiple() as $variant => $sitemap) { + $entity_manager = $this->generator->entityManager(); + foreach ($entity_manager->getSitemaps() as $variant => $sitemap) { $settings = $form_state->getValue(['simple_sitemap', $variant]); // Variants may have changed since form load. if ($settings) { - $this->generator - ->setVariants($variant) - ->entityManager() + $entity_manager + ->setSitemaps($sitemap) ->setBundleSettings($this->entityTypeId, $this->bundleName, $settings); } } diff --git a/web/modules/simple_sitemap/src/Form/Handler/EntityFormHandler.php b/web/modules/simple_sitemap/src/Form/Handler/EntityFormHandler.php index b9c2870b1ff83852f437cd358eed687dc0932ccd..49e881be55b58a089a83116a92784ced51885a0d 100644 --- a/web/modules/simple_sitemap/src/Form/Handler/EntityFormHandler.php +++ b/web/modules/simple_sitemap/src/Form/Handler/EntityFormHandler.php @@ -3,7 +3,6 @@ namespace Drupal\simple_sitemap\Form\Handler; use Drupal\Core\Form\FormStateInterface; -use Drupal\simple_sitemap\Entity\SimpleSitemap; use Drupal\simple_sitemap\Form\FormHelper; /** @@ -37,7 +36,7 @@ public function settingsForm(array $form): array { $bundle_label = $this->entityHelper ->getBundleLabel($this->entityTypeId, $this->bundleName); - foreach (SimpleSitemap::loadMultiple() as $variant => $sitemap) { + foreach ($this->generator->entityManager()->getSitemaps() as $variant => $sitemap) { $variant_form = &$form[$variant]; $variant_form['index']['#options'] = [ @@ -112,15 +111,14 @@ public function submitForm(array &$form, FormStateInterface $form_state) { return; } - // @todo No need to load all sitemaps here. - foreach (SimpleSitemap::loadMultiple() as $variant => $sitemap) { + $entity_manager = $this->generator->entityManager(); + foreach ($entity_manager->getSitemaps() as $variant => $sitemap) { $settings = $form_state->getValue(['simple_sitemap', $variant]); // Variants may have changed since form load. if ($settings) { - $this->generator - ->setVariants($variant) - ->entityManager() + $entity_manager + ->setSitemaps($sitemap) ->setEntityInstanceSettings($this->entityTypeId, $this->entity->id(), $settings); } } @@ -138,8 +136,8 @@ protected function getSettings(): array { foreach (parent::getSettings() as $variant => $settings) { if (NULL !== $entity_id) { $this->settings[$variant] = $this->generator - ->setVariants($variant) ->entityManager() + ->setSitemaps($variant) ->getEntityInstanceSettings($this->entityTypeId, $entity_id)[$variant]; } $this->settings[$variant]['bundle_settings'] = $settings; diff --git a/web/modules/simple_sitemap/src/Form/Handler/EntityFormHandlerBase.php b/web/modules/simple_sitemap/src/Form/Handler/EntityFormHandlerBase.php index bcccb2a45c419e651aef6cc9ca196d312d9a32fb..c7c0f2353a9cfdfc65b62a522b3fc7989895467c 100644 --- a/web/modules/simple_sitemap/src/Form/Handler/EntityFormHandlerBase.php +++ b/web/modules/simple_sitemap/src/Form/Handler/EntityFormHandlerBase.php @@ -2,18 +2,17 @@ namespace Drupal\simple_sitemap\Form\Handler; -use Drupal\Core\Url; -use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\DependencyInjection\DependencySerializationTrait; -use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Entity\EntityFormInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Element; -use Drupal\simple_sitemap\Entity\SimpleSitemap; +use Drupal\Core\StringTranslation\StringTranslationTrait; +use Drupal\Core\Url; use Drupal\simple_sitemap\Entity\EntityHelper; -use Drupal\simple_sitemap\Manager\Generator; use Drupal\simple_sitemap\Form\FormHelper; +use Drupal\simple_sitemap\Manager\Generator; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Defines a base class for altering an entity form. @@ -139,38 +138,41 @@ public function formAlter(array &$form, FormStateInterface $form_state) { * {@inheritdoc} */ public function settingsForm(array $form): array { - $sitemaps = SimpleSitemap::loadMultiple(); + $sitemaps = $this->generator->entityManager()->getSitemaps(); $settings = $this->getSettings(); if ($sitemaps) { $form['#markup'] = '<strong>' . $this->t('Sitemaps') . '</strong>'; } else { $form['#markup'] = $this->t('At least one sitemap needs to be defined for a bundle to be indexable.<br>Sitemaps can be configured <a href="@url">here</a>.', - ['@url' => Url::fromRoute('entity.simple_sitemap.collection')->toString(),] + ['@url' => Url::fromRoute('entity.simple_sitemap.collection')->toString()] ); } foreach ($sitemaps as $variant => $sitemap) { - $variant_form = &$form[$variant]; - - $variant_form = [ - '#type' => 'details', - '#title' => '<em>' . $sitemap->label() . '</em>', - '#open' => !empty($settings[$variant]['index']), - ]; - - $variant_form = $this->formHelper - ->settingsForm($variant_form, $settings[$variant]); - - $variant_form['index']['#attributes']['data-simple-sitemap-label'] = $sitemap->label(); - $variant_form['index']['#type'] = 'radios'; - $variant_form['index']['#title'] = NULL; - - $variant_form['index']['#options'] = [ - $this->t('Do not index entities of this type in sitemap <em>@sitemap</em>', ['@sitemap' => $sitemap->label()]), - $this->t('Index entities of this type in sitemap <em>@sitemap</em>', ['@sitemap' => $sitemap->label()]), - ]; + if ($settings[$variant]) { + $variant_form = &$form[$variant]; + + $variant_form = [ + '#type' => 'details', + '#title' => '<em>' . $sitemap->label() . '</em>', + '#open' => !empty($settings[$variant]['index']), + ]; + + $variant_form = $this->formHelper + ->settingsForm($variant_form, $settings[$variant]); + + $variant_form['index']['#attributes']['data-simple-sitemap-label'] = $sitemap->label(); + $variant_form['index']['#type'] = 'radios'; + $variant_form['index']['#title'] = NULL; + + $variant_form['index']['#options'] = [ + $this->t('Do not index entities of this type in sitemap <em>@sitemap</em>', ['@sitemap' => $sitemap->label()]), + $this->t('Index entities of this type in sitemap <em>@sitemap</em>', ['@sitemap' => $sitemap->label()]), + ]; + } } + return $form; } @@ -238,10 +240,11 @@ protected function processFormState(FormStateInterface $form_state) { protected function getSettings(): array { if (!isset($this->settings)) { $this->settings = $this->generator - ->setVariants() ->entityManager() + ->setSitemaps() ->getBundleSettings($this->entityTypeId, $this->bundleName); } + return $this->settings; } diff --git a/web/modules/simple_sitemap/src/Manager/CustomLinkManager.php b/web/modules/simple_sitemap/src/Manager/CustomLinkManager.php index dbfe1824d0f08f1fae42d89abf02633f4e761a69..f4fdcce4e09df96f248098e4f119f12639ad1cfa 100644 --- a/web/modules/simple_sitemap/src/Manager/CustomLinkManager.php +++ b/web/modules/simple_sitemap/src/Manager/CustomLinkManager.php @@ -4,13 +4,14 @@ use Drupal\Core\Path\PathValidatorInterface; use Drupal\Core\Config\ConfigFactoryInterface; +use Drupal\simple_sitemap\Entity\SimpleSitemap; /** * The simple_sitemap.custom_link_manager service. */ -class CustomLinkManager { +class CustomLinkManager implements SitemapGetterInterface { - use VariantSetterTrait; + use SitemapGetterTrait; use LinkSettingsTrait; /** @@ -68,11 +69,11 @@ public function __construct( * @todo Validate $settings. */ public function add(string $path, array $settings = []): CustomLinkManager { - if (empty($variants = $this->getVariants())) { + if (empty($variants = array_keys($this->getSitemaps()))) { return $this; } - if (!(bool) $this->pathValidator->getUrlIfValidWithoutAccessCheck($path)) { + if (!$this->pathValidator->getUrlIfValidWithoutAccessCheck($path)) { throw new \InvalidArgumentException("The path '$path' must be local and known to Drupal."); } if ($path[0] !== '/') { @@ -113,7 +114,7 @@ public function add(string $path, array $settings = []): CustomLinkManager { */ public function get(?string $path = NULL): array { $all_custom_links = []; - foreach ($this->getVariants() as $variant) { + foreach (array_keys($this->getSitemaps()) as $variant) { $custom_links = $this->configFactory ->get("simple_sitemap.custom_links.$variant") ->get('links'); @@ -137,9 +138,7 @@ public function get(?string $path = NULL): array { ? array_values($custom_links)[0] : array_values($custom_links); - if ($custom_links) { - $all_custom_links[$variant] = $custom_links; - } + $all_custom_links[$variant] = $custom_links; } return $all_custom_links; @@ -154,7 +153,7 @@ public function get(?string $path = NULL): array { * @return $this */ public function remove($paths = NULL): CustomLinkManager { - if (empty($variants = $this->getVariants())) { + if (empty($variants = array_keys($this->getSitemaps()))) { return $this; } @@ -188,4 +187,21 @@ public function remove($paths = NULL): CustomLinkManager { return $this; } + /** + * Gets all compatible sitemaps. + * + * @return \Drupal\simple_sitemap\Entity\SimpleSitemap[] + * Array of sitemaps of a type that implements a custom URL + * generator. + */ + protected function getCompatibleSitemaps(): array { + foreach (SimpleSitemap::loadMultiple() as $variant => $sitemap) { + if ($sitemap->getType()->hasUrlGenerator('custom')) { + $sitemaps[$variant] = $sitemap; + } + } + + return $sitemaps ?? []; + } + } diff --git a/web/modules/simple_sitemap/src/Manager/EntityManager.php b/web/modules/simple_sitemap/src/Manager/EntityManager.php index 78d34a75553bfb6dfab83deccb5e100bff3d981b..7272c19232dd025f010b3e3af1686f97b5253d05 100644 --- a/web/modules/simple_sitemap/src/Manager/EntityManager.php +++ b/web/modules/simple_sitemap/src/Manager/EntityManager.php @@ -2,19 +2,21 @@ namespace Drupal\simple_sitemap\Manager; +use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Database\Connection; use Drupal\Core\Entity\EntityFieldManagerInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; -use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\simple_sitemap\Entity\EntityHelper; +use Drupal\simple_sitemap\Entity\SimpleSitemap; +use Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator\EntityUrlGeneratorBase; use Drupal\simple_sitemap\Settings; /** * The simple_sitemap.entity_manager service. */ -class EntityManager { +class EntityManager implements SitemapGetterInterface { - use VariantSetterTrait; + use SitemapGetterTrait; use LinkSettingsTrait; /** @@ -171,7 +173,7 @@ public function disableEntityType(string $entity_type_id): EntityManager { } // Deleting entity overrides. - $this->setVariants()->removeEntityInstanceSettings($entity_type_id); + $this->setSitemaps()->removeEntityInstanceSettings($entity_type_id); return $this; } @@ -198,7 +200,7 @@ public function disableEntityType(string $entity_type_id): EntityManager { * @todo Throw exception on non-existing entity type/bundle. */ public function setBundleSettings(string $entity_type_id, ?string $bundle_name = NULL, array $settings = ['index' => TRUE]): EntityManager { - if (empty($variants = $this->getVariants())) { + if (empty($variants = array_keys($this->getSitemaps()))) { return $this; } if (!isset($this->entityHelper->getSupportedEntityTypes()[$entity_type_id])) { @@ -254,7 +256,7 @@ public function setBundleSettings(string $entity_type_id, ?string $bundle_name = $delete_instances = []; foreach ($query->execute()->fetchAll() as $result) { $delete = TRUE; - $instance_settings = unserialize($result->inclusion_settings); + $instance_settings = unserialize($result->inclusion_settings, ['allowed_classes' => FALSE]); foreach ($instance_settings as $setting_key => $instance_setting) { if ($instance_setting != $settings[$setting_key]) { $delete = FALSE; @@ -305,7 +307,7 @@ public function getBundleSettings(string $entity_type_id, ?string $bundle_name = $bundle_name = $bundle_name ?? $entity_type_id; $all_bundle_settings = []; - foreach ($this->getVariants() as $variant) { + foreach (array_keys($this->getSitemaps()) as $variant) { $bundle_settings = $this->configFactory ->get("simple_sitemap.bundle_settings.$variant.$entity_type_id.$bundle_name") ->get(); @@ -329,7 +331,7 @@ public function getBundleSettings(string $entity_type_id, ?string $bundle_name = */ public function getAllBundleSettings() { $all_bundle_settings = []; - foreach ($this->getVariants() as $variant) { + foreach (array_keys($this->getSitemaps()) as $variant) { $config_names = $this->configFactory->listAll("simple_sitemap.bundle_settings.$variant."); $bundle_settings = []; foreach ($config_names as $config_name) { @@ -368,7 +370,7 @@ public function getAllBundleSettings() { * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException */ public function removeBundleSettings(?string $entity_type_id = NULL, ?string $bundle_name = NULL): EntityManager { - if (empty($variants = $this->getVariants())) { + if (empty($variants = array_keys($this->getSitemaps()))) { return $this; } @@ -415,7 +417,7 @@ public function removeBundleSettings(?string $entity_type_id = NULL, ?string $bu * @todo Pass entity object instead of id and entity type? */ public function setEntityInstanceSettings(string $entity_type_id, string $id, array $settings): EntityManager { - if (empty($variants = $this->getVariants())) { + if (empty($variants = array_keys($this->getSitemaps()))) { return $this; } @@ -432,7 +434,7 @@ public function setEntityInstanceSettings(string $entity_type_id, string $id, ar if (!empty($bundle_settings)) { // Only one variant at a time. - $this->setVariants($variant); + $this->setSitemaps($variant); // Check if overrides are different from bundle setting before saving. $override = FALSE; @@ -467,7 +469,7 @@ public function setEntityInstanceSettings(string $entity_type_id, string $id, ar } // Restore original variants. - $this->setVariants($variants); + $this->setSitemaps($variants); return $this; } @@ -496,7 +498,7 @@ public function setEntityInstanceSettings(string $entity_type_id, string $id, ar * @todo Pass entity object instead of id and entity type? */ public function getEntityInstanceSettings(string $entity_type_id, string $id) { - if (empty($variants = $this->getVariants())) { + if (empty($variants = array_keys($this->getSitemaps()))) { return FALSE; } $variant = reset($variants); @@ -510,7 +512,7 @@ public function getEntityInstanceSettings(string $entity_type_id, string $id) { ->fetchField(); if (!empty($results)) { - return [$variant => unserialize($results)]; + return [$variant => unserialize($results, ['allowed_classes' => FALSE])]; } if (($entity = $this->entityTypeManager->getStorage($entity_type_id)->load($id)) === NULL) { @@ -538,7 +540,7 @@ public function getEntityInstanceSettings(string $entity_type_id, string $id) { * @return $this */ public function removeEntityInstanceSettings(?string $entity_type_id = NULL, $entity_ids = NULL): EntityManager { - if (empty($variants = $this->getVariants())) { + if (empty($variants = array_keys($this->getSitemaps()))) { return $this; } @@ -595,4 +597,28 @@ public function entityTypeIsEnabled(string $entity_type_id): bool { return in_array($entity_type_id, $this->settings->get('enabled_entity_types', []), TRUE); } + /** + * Gets all compatible sitemaps. + * + * @return \Drupal\simple_sitemap\Entity\SimpleSitemap[] + * Array of sitemaps of a type that uses a URL generator which + * extends EntityUrlGeneratorBase. Keyed by variant. + * + * @todo This is not ideal as it shows only-menu-link-sitemaps on all bundle + * setting pages and vice versa. It also shows only-custom-link-sitemaps on + * all bundle setting pages and vice versa. + */ + protected function getCompatibleSitemaps(): array { + foreach (SimpleSitemap::loadMultiple() as $variant => $sitemap) { + foreach ($sitemap->getType()->getUrlGenerators() as $url_generator) { + if ($url_generator instanceof EntityUrlGeneratorBase) { + $sitemaps[$variant] = $sitemap; + break; + } + } + } + + return $sitemaps ?? []; + } + } diff --git a/web/modules/simple_sitemap/src/Manager/Generator.php b/web/modules/simple_sitemap/src/Manager/Generator.php index dd918c60bc58f5de44abe34ff8bf2a29ee2b724b..17f5587d412389246de1ec32cddac00e31581229 100644 --- a/web/modules/simple_sitemap/src/Manager/Generator.php +++ b/web/modules/simple_sitemap/src/Manager/Generator.php @@ -15,9 +15,9 @@ * the sitemap. Services for custom link and entity link generation can be * fetched from this service as well. */ -class Generator { +class Generator implements SitemapGetterInterface { - use VariantSetterTrait; + use SitemapGetterTrait; /** * The simple_sitemap.settings service. @@ -107,21 +107,35 @@ public function saveSetting(string $name, $setting): Generator { * * @return string|null * The default variant or NULL if there are no variants. + * + * @deprecated in simple_sitemap:4.1.7 and is removed from simple_sitemap:5.0.0. + * Use getDefaultSitemap() instead. + * @see https://www.drupal.org/project/simple_sitemap/issues/3375932 */ public function getDefaultVariant(): ?string { - if (empty($variants = $this->getVariants())) { + return $this->getDefaultSitemap()?->id(); + } + + /** + * Gets the default sitemap from the currently set sitemaps. + * + * @return \Drupal\simple_sitemap\Entity\SimpleSitemap|null + * The default sitemap or NULL if there are no sitemaps. + */ + public function getDefaultSitemap(): ?SimpleSitemap { + if (empty($sitemaps = $this->getSitemaps())) { return NULL; } - if (count($variants) > 1) { + if (count($sitemaps) > 1) { $variant = $this->getSetting('default_variant'); - if ($variant && in_array($variant, $variants)) { - return $variant; + if ($variant && array_key_exists($variant, $sitemaps)) { + return $sitemaps[$variant]; } } - return reset($variants); + return reset($sitemaps); } /** @@ -137,10 +151,11 @@ public function getDefaultVariant(): ?string { * Returns null if the content is not retrievable from the database. */ public function getContent(?int $delta = NULL): ?string { - $variant = $this->getDefaultVariant(); + $sitemap = $this->getDefaultSitemap(); /** @var \Drupal\simple_sitemap\Entity\SimpleSitemapInterface $sitemap */ - if ($variant && ($sitemap = SimpleSitemap::load($variant)) && $sitemap->isEnabled() + if ($sitemap + && $sitemap->isEnabled() && ($sitemap_string = $sitemap->fromPublished()->toString($delta))) { return $sitemap_string; } @@ -186,7 +201,7 @@ public function generate(string $from = QueueWorker::GENERATE_TYPE_FORM): Genera * @throws \Drupal\Component\Plugin\Exception\PluginException */ public function queue(): Generator { - $this->queueWorker->queue($this->getVariants()); + $this->queueWorker->queue($this->getSitemaps()); return $this; } @@ -203,7 +218,7 @@ public function rebuildQueue(): Generator { $this->logger->m('Unable to acquire a lock for sitemap generation.')->log('error')->display('error'); return $this; } - $this->queueWorker->rebuildQueue($this->getVariants()); + $this->queueWorker->rebuildQueue($this->getSitemaps()); return $this; } @@ -215,10 +230,14 @@ public function rebuildQueue(): Generator { * The simple_sitemap.entity_manager service. */ public function entityManager(): EntityManager { - /** @var \Drupal\simple_sitemap\Manager\EntityManager $entities */ - $entities = \Drupal::service('simple_sitemap.entity_manager'); + /** @var \Drupal\simple_sitemap\Manager\EntityManager $entity_manager */ + $entity_manager = \Drupal::service('simple_sitemap.entity_manager'); + + if ($this->sitemaps !== NULL) { + $entity_manager->setSitemaps($this->getSitemaps()); + } - return $entities->setVariants($this->getVariants()); + return $entity_manager; } /** @@ -228,10 +247,24 @@ public function entityManager(): EntityManager { * The simple_sitemap.custom_link_manager service. */ public function customLinkManager(): CustomLinkManager { - /** @var \Drupal\simple_sitemap\Manager\CustomLinkManager $custom_links */ - $custom_links = \Drupal::service('simple_sitemap.custom_link_manager'); + /** @var \Drupal\simple_sitemap\Manager\CustomLinkManager $custom_link_manager */ + $custom_link_manager = \Drupal::service('simple_sitemap.custom_link_manager'); - return $custom_links->setVariants($this->getVariants()); + if ($this->sitemaps !== NULL) { + $custom_link_manager->setSitemaps($this->getSitemaps()); + } + + return $custom_link_manager; + } + + /** + * Gets all compatible sitemaps. + * + * @return \Drupal\simple_sitemap\Entity\SimpleSitemap[] + * Array of sitemaps. + */ + protected function getCompatibleSitemaps(): array { + return SimpleSitemap::loadMultiple(); } } diff --git a/web/modules/simple_sitemap/src/Manager/SitemapGetterInterface.php b/web/modules/simple_sitemap/src/Manager/SitemapGetterInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..41e64e4c968ea12973d3852dfeb8d62aa1dc692a --- /dev/null +++ b/web/modules/simple_sitemap/src/Manager/SitemapGetterInterface.php @@ -0,0 +1,32 @@ +<?php + +namespace Drupal\simple_sitemap\Manager; + +/** + * Provides an interface to setting/getting sitemaps. + */ +interface SitemapGetterInterface { + + /** + * Gets the currently set sitemaps. + * + * @return \Drupal\simple_sitemap\Entity\SimpleSitemap[] + * The currently set sitemaps, or all compatible sitemaps if none are set. + */ + public function getSitemaps(): array; + + /** + * Sets the sitemaps. + * + * @param \Drupal\simple_sitemap\Entity\SimpleSitemap[]|\Drupal\simple_sitemap\Entity\SimpleSitemap|string[]|string|null $sitemaps + * SimpleSitemap[]: Array of sitemap objects to be set. + * string[]: Array of sitemap IDs to be set. + * SimpleSitemap: A particular sitemap object to be set. + * string: A particular sitemap ID to be set. + * null: All compatible sitemaps will be set. + * + * @return $this + */ + public function setSitemaps($sitemaps = NULL): self; + +} diff --git a/web/modules/simple_sitemap/src/Manager/SitemapGetterTrait.php b/web/modules/simple_sitemap/src/Manager/SitemapGetterTrait.php new file mode 100644 index 0000000000000000000000000000000000000000..c0ea09d0667e613d567f8db1deb741996f3bb7bf --- /dev/null +++ b/web/modules/simple_sitemap/src/Manager/SitemapGetterTrait.php @@ -0,0 +1,75 @@ +<?php + +namespace Drupal\simple_sitemap\Manager; + +use Drupal\simple_sitemap\Entity\SimpleSitemap; + +/** + * Provides a helper to setting/getting sitemaps. + */ +trait SitemapGetterTrait { + + /** + * The currently set sitemaps. + * + * @var \Drupal\simple_sitemap\Entity\SimpleSitemap[] + */ + protected $sitemaps; + + /** + * Sets the variants. + * + * @param array|string|null $variants + * array: Array of variants to be set. + * string: A particular variant to be set. + * null: All compatible variants will be set. + * + * @return $this + * + * @deprecated in simple_sitemap:4.1.7 and is removed from simple_sitemap:5.0.0. + * Use setSitemaps() instead. + * @see https://www.drupal.org/project/simple_sitemap/issues/3375932 + */ + public function setVariants($variants = NULL): self { + return $this->setSitemaps($variants); + } + + /** + * {@inheritdoc} + */ + public function setSitemaps($sitemaps = NULL): self { + if ($sitemaps === NULL) { + $this->sitemaps = static::getCompatibleSitemaps(); + } + else { + // Not casting to array here directly, because $sitemaps could be an + // object. + $sitemaps = !is_array($sitemaps) ? [$sitemaps] : $sitemaps; + + if ($sitemaps && !($sitemaps[array_key_first($sitemaps)] instanceof SimpleSitemap)) { + $sitemaps = SimpleSitemap::loadMultiple($sitemaps); + } + else { + // Make sure the array keys are sitemap IDs. + foreach ($sitemaps as $sitemap) { + $sitemaps_by_id[$sitemap->id()] = $sitemap; + } + } + $this->sitemaps = $sitemaps_by_id ?? $sitemaps; + } + + return $this; + } + + /** + * {@inheritdoc} + */ + public function getSitemaps(): array { + if (NULL === $this->sitemaps) { + $this->setSitemaps(); + } + + return $this->sitemaps; + } + +} diff --git a/web/modules/simple_sitemap/src/Manager/VariantSetterTrait.php b/web/modules/simple_sitemap/src/Manager/VariantSetterTrait.php deleted file mode 100644 index e8da198642fcc7e2d00deeb1fc967112a73d7d79..0000000000000000000000000000000000000000 --- a/web/modules/simple_sitemap/src/Manager/VariantSetterTrait.php +++ /dev/null @@ -1,57 +0,0 @@ -<?php - -namespace Drupal\simple_sitemap\Manager; - -use Drupal\simple_sitemap\Entity\SimpleSitemap; - -/** - * Provides a helper to setting/getting variants. - */ -trait VariantSetterTrait { - - /** - * The currently set variants. - * - * @var array - */ - protected $variants; - - /** - * Sets the variants. - * - * @param array|string|null $variants - * array: Array of variants to be set. - * string: A particular variant to be set. - * null: All existing variants will be set. - * - * @return $this - * - * @todo Check if variants exist and throw exception. - */ - public function setVariants($variants = NULL): self { - if ($variants === NULL) { - // @todo No need to load all sitemaps here. - $this->variants = array_keys(SimpleSitemap::loadMultiple()); - } - else { - $this->variants = (array) $variants; - } - - return $this; - } - - /** - * Gets the currently set variants, or all variants if none are set. - * - * @return array - * The currently set variants, or all variants if none are set. - */ - protected function getVariants(): array { - if (NULL === $this->variants) { - $this->setVariants(); - } - - return $this->variants; - } - -} diff --git a/web/modules/simple_sitemap/src/Plugin/simple_sitemap/UrlGenerator/CustomUrlGenerator.php b/web/modules/simple_sitemap/src/Plugin/simple_sitemap/UrlGenerator/CustomUrlGenerator.php index 73004de9c0d7250311ce884f2e5c9523a7a53f92..2710e760229adf4929daba69883d8a16be71bd4f 100644 --- a/web/modules/simple_sitemap/src/Plugin/simple_sitemap/UrlGenerator/CustomUrlGenerator.php +++ b/web/modules/simple_sitemap/src/Plugin/simple_sitemap/UrlGenerator/CustomUrlGenerator.php @@ -126,7 +126,7 @@ public static function create( public function getDataSets(): array { $this->includeImages = $this->settings->get('custom_links_include_images', FALSE); - $custom_link_settings = $this->customLinks->setVariants($this->sitemap->id())->get(); + $custom_link_settings = $this->customLinks->setSitemaps($this->sitemap)->get(); $custom_link_settings = $custom_link_settings ? reset($custom_link_settings) : []; return array_values($custom_link_settings); diff --git a/web/modules/simple_sitemap/src/Plugin/simple_sitemap/UrlGenerator/EntityMenuLinkContentUrlGenerator.php b/web/modules/simple_sitemap/src/Plugin/simple_sitemap/UrlGenerator/EntityMenuLinkContentUrlGenerator.php index 2bba000d9e753663c34251e685efa91259669a1d..a3cb618b4df84ac55c242fd6ed447d477cc58a87 100644 --- a/web/modules/simple_sitemap/src/Plugin/simple_sitemap/UrlGenerator/EntityMenuLinkContentUrlGenerator.php +++ b/web/modules/simple_sitemap/src/Plugin/simple_sitemap/UrlGenerator/EntityMenuLinkContentUrlGenerator.php @@ -2,17 +2,19 @@ namespace Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator; +use Drupal\Component\Plugin\Exception\PluginException; +use Drupal\Core\Entity\EntityTypeManagerInterface; +use Drupal\Core\Language\LanguageManagerInterface; +use Drupal\Core\Menu\MenuLinkManagerInterface; +use Drupal\Core\Menu\MenuLinkTreeInterface; +use Drupal\Core\Menu\MenuTreeParameters; use Drupal\simple_sitemap\Entity\EntityHelper; use Drupal\simple_sitemap\Exception\SkipElementException; use Drupal\simple_sitemap\Logger; use Drupal\simple_sitemap\Manager\EntityManager; use Drupal\simple_sitemap\Plugin\simple_sitemap\SimpleSitemapPluginBase; -use Drupal\Core\Language\LanguageManagerInterface; -use Drupal\Core\Entity\EntityTypeManagerInterface; -use Drupal\Core\Menu\MenuTreeParameters; use Drupal\simple_sitemap\Settings; use Symfony\Component\DependencyInjection\ContainerInterface; -use Drupal\Core\Menu\MenuLinkTreeInterface; /** * Provides the menu link URL generator. @@ -25,8 +27,6 @@ * "overrides_entity_type" = "menu_link_content", * }, * ) - * - * @todo Find way of adding just a menu link item pointer to the queue instead of whole object. */ class EntityMenuLinkContentUrlGenerator extends EntityUrlGeneratorBase { @@ -44,6 +44,13 @@ class EntityMenuLinkContentUrlGenerator extends EntityUrlGeneratorBase { */ protected $entitiesManager; + /** + * The menu link plugin manager. + * + * @var \Drupal\Core\Menu\MenuLinkManagerInterface + */ + protected $menuLinkManager; + /** * EntityMenuLinkContentUrlGenerator constructor. * @@ -67,6 +74,8 @@ class EntityMenuLinkContentUrlGenerator extends EntityUrlGeneratorBase { * The simple_sitemap.entity_manager service. * @param \Drupal\Core\Menu\MenuLinkTreeInterface $menu_link_tree * The menu tree service. + * @param \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager + * The menu link plugin manager. */ public function __construct( array $configuration, @@ -78,7 +87,8 @@ public function __construct( EntityTypeManagerInterface $entity_type_manager, EntityHelper $entity_helper, EntityManager $entities_manager, - MenuLinkTreeInterface $menu_link_tree + MenuLinkTreeInterface $menu_link_tree, + MenuLinkManagerInterface $menu_link_manager ) { parent::__construct( $configuration, @@ -92,6 +102,7 @@ public function __construct( ); $this->entitiesManager = $entities_manager; $this->menuLinkTree = $menu_link_tree; + $this->menuLinkManager = $menu_link_manager; } /** @@ -112,7 +123,8 @@ public static function create( $container->get('entity_type.manager'), $container->get('simple_sitemap.entity_helper'), $container->get('simple_sitemap.entity_manager'), - $container->get('menu.link_tree') + $container->get('menu.link_tree'), + $container->get('plugin.manager.menu.link') ); } @@ -122,7 +134,7 @@ public static function create( public function getDataSets(): array { $data_sets = []; $bundle_settings = $this->entitiesManager - ->setVariants($this->sitemap->id()) + ->setSitemaps($this->sitemap) ->getAllBundleSettings(); if (!empty($bundle_settings[$this->sitemap->id()]['menu_link_content'])) { foreach ($bundle_settings[$this->sitemap->id()]['menu_link_content'] as $bundle_name => $settings) { @@ -136,7 +148,7 @@ public function getDataSets(): array { ]); foreach ($tree as $item) { - $data_sets[] = $item->link; + $data_sets[] = $item->link->getPluginId(); } } } @@ -147,10 +159,14 @@ public function getDataSets(): array { /** * {@inheritdoc} - * - * @todo Find a way to be able to check if a menu link still exists. This is difficult as we don't operate on MenuLinkContent entities, but on Link entities directly (as some menu links are not MenuLinkContent entities). */ protected function processDataSet($data_set): array { + try { + $data_set = $this->menuLinkManager->createInstance($data_set); + } + catch (PluginException $e) { + throw new SkipElementException(); + } /** @var \Drupal\Core\Menu\MenuLinkInterface $data_set */ if (!$data_set->isEnabled()) { @@ -168,7 +184,7 @@ protected function processDataSet($data_set): array { $meta_data = $data_set->getMetaData(); if (empty($meta_data['entity_id'])) { $entity_settings = $this->entitiesManager - ->setVariants($this->sitemap->id()) + ->setSitemaps($this->sitemap) ->getBundleSettings('menu_link_content', $data_set->getMenuName()); } @@ -176,7 +192,7 @@ protected function processDataSet($data_set): array { // entity override. else { $entity_settings = $this->entitiesManager - ->setVariants($this->sitemap->id()) + ->setSitemaps($this->sitemap) ->getEntityInstanceSettings('menu_link_content', $meta_data['entity_id']); } if (empty($entity_settings[$this->sitemap->id()]['index'])) { diff --git a/web/modules/simple_sitemap/src/Plugin/simple_sitemap/UrlGenerator/EntityUrlGenerator.php b/web/modules/simple_sitemap/src/Plugin/simple_sitemap/UrlGenerator/EntityUrlGenerator.php index 3ad4dc79540a01dee4920c2f5c10d8ff0e05f35e..d86775b0f1f5ac4b79ab2e09c6926bb68d3345a9 100644 --- a/web/modules/simple_sitemap/src/Plugin/simple_sitemap/UrlGenerator/EntityUrlGenerator.php +++ b/web/modules/simple_sitemap/src/Plugin/simple_sitemap/UrlGenerator/EntityUrlGenerator.php @@ -138,7 +138,7 @@ public static function create( public function getDataSets(): array { $data_sets = []; $sitemap_entity_types = $this->entityHelper->getSupportedEntityTypes(); - $all_bundle_settings = $this->entitiesManager->setVariants($this->sitemap->id())->getAllBundleSettings(); + $all_bundle_settings = $this->entitiesManager->setSitemaps($this->sitemap)->getAllBundleSettings(); if (isset($all_bundle_settings[$this->sitemap->id()])) { foreach ($all_bundle_settings[$this->sitemap->id()] as $entity_type_name => $bundles) { if (!isset($sitemap_entity_types[$entity_type_name])) { @@ -162,6 +162,8 @@ public function getDataSets(): array { if (!empty($keys['bundle'])) { $query->condition($keys['bundle'], $bundle_name); } + + // @todo Remove the below and add hooks for greater flexibility. if (!empty($keys['published'])) { $query->condition($keys['published'], 1); } @@ -248,7 +250,7 @@ protected function processDataSet($data_set): array { */ protected function processEntity(ContentEntityInterface $entity): array { $entity_settings = $this->entitiesManager - ->setVariants($this->sitemap->id()) + ->setSitemaps($this->sitemap) ->getEntityInstanceSettings($entity->getEntityTypeId(), $entity->id()); if (empty($entity_settings[$this->sitemap->id()]['index'])) { diff --git a/web/modules/simple_sitemap/src/Plugin/simple_sitemap/UrlGenerator/SitemapIndexUrlGenerator.php b/web/modules/simple_sitemap/src/Plugin/simple_sitemap/UrlGenerator/SitemapIndexUrlGenerator.php index 17772c2f1a9712772b038a18d6aab38c971e5d03..eab8651f3dc6938fa30ed39189cc848decd1bdbc 100644 --- a/web/modules/simple_sitemap/src/Plugin/simple_sitemap/UrlGenerator/SitemapIndexUrlGenerator.php +++ b/web/modules/simple_sitemap/src/Plugin/simple_sitemap/UrlGenerator/SitemapIndexUrlGenerator.php @@ -32,6 +32,10 @@ public function getDataSets(): array { /** * {@inheritdoc} + * + * @todo May need to implement a way of saving which sitemaps to index with + * each sitemap index. Right now all sitemaps that are not of a type that + * implements the sitemap index generator are indexed. */ protected function processDataSet($data_set): array { if (($sitemap = SimpleSitemap::load($data_set)) diff --git a/web/modules/simple_sitemap/src/Queue/QueueWorker.php b/web/modules/simple_sitemap/src/Queue/QueueWorker.php index 4011e92845e7b6915bd46f70ce86f2408c1ffd25..6ca845e01f4b11e68089bbfcdc2353b4964a5b8c 100644 --- a/web/modules/simple_sitemap/src/Queue/QueueWorker.php +++ b/web/modules/simple_sitemap/src/Queue/QueueWorker.php @@ -167,21 +167,16 @@ public function __construct(Settings $settings, } /** - * Queues links from variants. + * Queues links from sitemaps. * - * @param string[]|string|null $variants - * The sitemap variants. + * @param \Drupal\simple_sitemap\Entity\SimpleSitemap[] $sitemaps + * The sitemaps. * * @return $this * * @throws \Drupal\Component\Plugin\Exception\PluginException */ - public function queue($variants = NULL): QueueWorker { - $variants = $variants !== NULL ? (array) $variants : NULL; - - /** @var \Drupal\simple_sitemap\Entity\SimpleSitemap[] $sitemaps */ - $sitemaps = $this->entityTypeManager->getStorage('simple_sitemap')->loadMultiple($variants); - + public function queue($sitemaps = []): QueueWorker { $empty_variants = array_fill_keys(array_keys($sitemaps), TRUE); $all_data_sets = []; @@ -221,21 +216,21 @@ public function queue($variants = NULL): QueueWorker { } /** - * Deletes the queue and queues links from variants. + * Deletes the queue and queues links from sitemaps. * - * @param string[]|string|null $variants - * The sitemap variants. + * @param \Drupal\simple_sitemap\Entity\SimpleSitemap[] $sitemaps + * The sitemaps. * * @return $this * * @throws \Drupal\Component\Plugin\Exception\PluginException */ - public function rebuildQueue($variants = NULL): QueueWorker { + public function rebuildQueue($sitemaps = []): QueueWorker { if (!$this->lock->acquire(static::LOCK_ID)) { throw new \RuntimeException('Unable to acquire a lock for sitemap queue rebuilding'); } $this->deleteQueue(); - $this->queue($variants); + $this->queue($sitemaps); $this->lock->release(static::LOCK_ID); return $this; @@ -283,7 +278,7 @@ public function generate(string $from = self::GENERATE_TYPE_FORM): QueueWorker { $this->unstashResults(); if (!$this->generationInProgress()) { - $this->rebuildQueue(); + $this->rebuildQueue(SimpleSitemap::loadMultiple()); } // Acquire a lock for max execution time + 5 seconds. If max_execution time diff --git a/web/modules/simple_sitemap/src/Queue/SimpleSitemapQueue.php b/web/modules/simple_sitemap/src/Queue/SimpleSitemapQueue.php index 0d2fd1e3c974c9520fd64b2a02e98ee112982ba6..6ce26f54501f05338240c96c7126052b069f4264 100644 --- a/web/modules/simple_sitemap/src/Queue/SimpleSitemapQueue.php +++ b/web/modules/simple_sitemap/src/Queue/SimpleSitemapQueue.php @@ -2,9 +2,9 @@ namespace Drupal\simple_sitemap\Queue; +use Drupal\Component\Datetime\TimeInterface; use Drupal\Core\Database\Connection; use Drupal\Core\Queue\DatabaseQueue; -use Drupal\Component\Datetime\TimeInterface; /** * Defines a Simple XML Sitemap queue handler. @@ -44,7 +44,7 @@ public function claimItem($lease_time = 0) { try { $item = $this->connection->queryRange('SELECT data, item_id FROM {queue} q WHERE name = :name ORDER BY item_id ASC', 0, 1, [':name' => $this->name])->fetchObject(); if ($item) { - $item->data = unserialize($item->data); + $item->data = unserialize($item->data, ['allowed_classes' => FALSE]); return $item; } } @@ -72,7 +72,7 @@ public function yieldItem(): \Generator { try { $query = $this->connection->query('SELECT data, item_id FROM {queue} q WHERE name = :name ORDER BY item_id ASC', [':name' => $this->name]); while ($item = $query->fetchObject()) { - $item->data = unserialize($item->data); + $item->data = unserialize($item->data, ['allowed_classes' => FALSE]); yield $item; } } diff --git a/web/modules/simple_sitemap/src/Settings.php b/web/modules/simple_sitemap/src/Settings.php index bcf65ec98f6dbd5a011694a2c067dc1f3e1ea840..aa354f834796d8a93676bfa1e525962579c66896 100644 --- a/web/modules/simple_sitemap/src/Settings.php +++ b/web/modules/simple_sitemap/src/Settings.php @@ -46,8 +46,9 @@ public function get(string $name, $default = NULL) { } /** - * Returns a specific setting (without config overrides) or a default value - * if setting does not exist. + * Returns a specific setting or a default value if setting does not exist. + * + * Same as above but without config overrides. * * @param string $name * Name of the setting, like 'max_links'. @@ -57,7 +58,7 @@ public function get(string $name, $default = NULL) { * @return mixed * The current setting from configuration or a default value. * - * @see https://www.drupal.org/project/simple_sitemap/issues/3359679. + * @see https://www.drupal.org/project/simple_sitemap/issues/3359679 */ public function getEditable(string $name, $default = NULL) { $setting = $this->configFactory diff --git a/web/modules/simple_sitemap/tests/src/Functional/SimplesitemapTest.php b/web/modules/simple_sitemap/tests/src/Functional/SimplesitemapTest.php index 636ca7c6a25d31a6ad2f9f2887bf2187063f9eab..c7affd54170a27ae02ada30dffd6230be5beffb8 100644 --- a/web/modules/simple_sitemap/tests/src/Functional/SimplesitemapTest.php +++ b/web/modules/simple_sitemap/tests/src/Functional/SimplesitemapTest.php @@ -661,7 +661,7 @@ public function testSitemapVariants() { $this->assertSession()->responseNotContains('node/' . $this->node->id()); $this->generator->entityManager()->setBundleSettings('node', 'page'); - $this->generator->setVariants('test')->generate(QueueWorker::GENERATE_TYPE_BACKEND); + $this->generator->setSitemaps('test')->generate(QueueWorker::GENERATE_TYPE_BACKEND); // Test if bundle settings have been set for correct variant. $this->drupalGet($this->defaultSitemapUrl);