Commit 1a3a4a10 authored by Pawel Ginalski's avatar Pawel Ginalski
Browse files

Issue #3299634 by jshimota01, gbyte: Undefined array key "loc" when generating sitemap

parent f415a102
Loading
Loading
Loading
Loading
+3 −5
Original line number Diff line number Diff line
@@ -81,7 +81,9 @@ class DefaultSitemapGenerator extends SitemapGeneratorBase {
   *   The array of properties for this URL.
   */
  protected function addUrl(array $url_data): void {
    if (isset($url_data['url'])) {
      $this->writer->writeElement('loc', $url_data['url']);
    }

    // If more than one language is enabled, add all translation variant URLs
    // as alternate links to this link turning the sitemap into a hreflang
@@ -90,22 +92,18 @@ class DefaultSitemapGenerator extends SitemapGeneratorBase {
      $this->addAlternateUrls($url_data['alternate_urls']);
    }

    // Add lastmod if any.
    if (isset($url_data['lastmod'])) {
      $this->writer->writeElement('lastmod', $url_data['lastmod']);
    }

    // Add changefreq if any.
    if (isset($url_data['changefreq'])) {
      $this->writer->writeElement('changefreq', $url_data['changefreq']);
    }

    // Add priority if any.
    if (isset($url_data['priority'])) {
      $this->writer->writeElement('priority', $url_data['priority']);
    }

    // Add images if any.
    if (!empty($url_data['images'])) {
      foreach ($url_data['images'] as $image) {
        $this->writer->startElement('image:image');
+9 −2
Original line number Diff line number Diff line
@@ -46,8 +46,15 @@ class SitemapIndexGenerator extends DefaultSitemapGenerator {
  protected function addLinks(array $links): void {
    foreach ($links as $url_data) {
      $this->writer->startElement('sitemap');
      $this->writer->writeElement('loc', $url_data['loc']);

      if (isset($url_data['url'])) {
        $this->writer->writeElement('loc', $url_data['url']);
      }

      if (isset($url_data['lastmod'])) {
        $this->writer->writeElement('lastmod', $url_data['lastmod']);
      }

      $this->writer->endElement();
    }
  }
+1 −1
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ class SitemapIndexUrlGenerator extends UrlGeneratorBase {
      $url_object = $sitemap->toUrl()->setAbsolute();

      return [
        'loc' => $url_object->toString(),
        'url' => $url_object->toString(),
        'lastmod' => date('c', $sitemap->fromPublished()->getCreated()),

        // Additional info useful in hooks.
+0 −2
Original line number Diff line number Diff line
@@ -2,8 +2,6 @@

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;