Commit 60a53819 authored by Pawel Ginalski's avatar Pawel Ginalski
Browse files

Issue #3178229 by gbyte, minorwm, WalkingDexter: Don't de-duplicate URLs with...

Issue #3178229 by gbyte, minorwm, WalkingDexter: Don't de-duplicate URLs with different query strings
parent fb9df180
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
namespace Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator;

use Drupal\Core\Url;
use Drupal\Component\Utility\UrlHelper;
use Drupal\simple_sitemap\Entity\EntityHelper;
use Drupal\simple_sitemap\Exception\SkipElementException;
use Drupal\simple_sitemap\Logger;
@@ -147,7 +148,6 @@ class CustomUrlGenerator extends EntityUrlGeneratorBase {
    }

    $url_object = Url::fromUserInput($data_set['path'])->setAbsolute();
    $path = $url_object->getInternalPath();

    $entity = $this->entityHelper->getEntityFromUrlObject($url_object);

@@ -162,10 +162,14 @@ class CustomUrlGenerator extends EntityUrlGeneratorBase {
      ? $this->getEntityImageData($entity)
      : [],
      'meta' => [
        'path' => $path,
        'path' => $this->getInternalPathWithQuery($url_object),
      ],
    ];

    if (($query = $url_object->getOption('query')) && is_array($query)) {
      $path_data['meta']['query'] = UrlHelper::buildQuery($query);
    }

    // Additional info useful in hooks.
    if (!empty($entity)) {
      $path_data['meta']['entity_info'] = [
+6 −8
Original line number Diff line number Diff line
@@ -191,19 +191,17 @@ class EntityMenuLinkContentUrlGenerator extends EntityUrlGeneratorBase {
        throw new SkipElementException();
      }

      $path = $url_object->getInternalPath();
      $path = $this->getInternalPathWithQuery($url_object);
    }
    // There can be internal paths that are not rooted, like 'base:/path'.
    else {
    elseif (strpos($uri = $url_object->toUriString(), 'base:/') === 0) {
      // Handle base scheme.
      if (strpos($uri = $url_object->toUriString(), 'base:/') === 0) {
      $path = $uri[6] === '/' ? substr($uri, 7) : substr($uri, 6);
    }
      // Handle unforeseen schemes.
    else {
      // Handle unforeseen schemes.
      $path = $uri;
    }
    }

    $entity = $this->entityHelper->getEntityFromUrlObject($url_object);

+1 −1
Original line number Diff line number Diff line
@@ -276,7 +276,7 @@ class EntityUrlGenerator extends EntityUrlGeneratorBase {

      // Additional info useful in hooks.
      'meta' => [
        'path' => $url_object->getInternalPath(),
        'path' => $this->getInternalPathWithQuery($url_object),
        'entity_info' => [
          'entity_type' => $entity->getEntityTypeId(),
          'id' => $entity->id(),
+19 −0
Original line number Diff line number Diff line
@@ -2,6 +2,8 @@

namespace Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator;

use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Url;
use Drupal\simple_sitemap\Exception\SkipElementException;
use Drupal\simple_sitemap\Plugin\simple_sitemap\SimpleSitemapPluginBase;
use Drupal\simple_sitemap\Entity\SimpleSitemapInterface;
@@ -98,6 +100,23 @@ abstract class UrlGeneratorBase extends SimpleSitemapPluginBase implements UrlGe
      : $url;
  }

  /**
   * Gets the internal path with URL query from a URL object.
   *
   * @param \Drupal\Core\Url $url
   *   URL object.
   *
   * @return string
   *   Internal path with URL query.
   */
  protected function getInternalPathWithQuery(Url $url): string {
    if (($query = $url->getOption('query')) && is_array($query)) {
      return $url->getInternalPath() . '?' . UrlHelper::buildQuery($query);
    }

    return $url->getInternalPath();
  }

  /**
   * {@inheritdoc}
   */
+9 −7
Original line number Diff line number Diff line
@@ -371,13 +371,15 @@ class QueueWorker {
   */
  protected function removeDuplicates(array &$results): void {
    if ($this->generatorSettings['remove_duplicates'] && !empty($results)) {
      $result = $results[key($results)];
      foreach ($results as $key => $result) {
        if (isset($result['meta']['path'])) {
        if (isset($this->processedPaths[$result['meta']['path']])) {
          $results = [];
          $path = $result['meta']['path'];
          if (isset($this->processedPaths[$path])) {
            unset($results[$key]);
          }
          else {
          $this->processedPaths[$result['meta']['path']] = TRUE;
            $this->processedPaths[$path] = TRUE;
          }
        }
      }
    }
Loading