[FEATURE] Support recursive in record sitemap 22/58822/8
authorGeorg Ringer <georg.ringer@gmail.com>
Thu, 1 Nov 2018 22:03:56 +0000 (23:03 +0100)
committerBenni Mack <benni@typo3.org>
Fri, 16 Nov 2018 10:46:59 +0000 (11:46 +0100)
A recursive configuration makes it a lot easier to provide
a sitemap for all records without touching the configuration
if a new sysfolder is created.

Resolves: #86826
Releases: master
Change-Id: I77d49a8fd45eeb8e5bf32575d6c986f66e9c9c55
Reviewed-on: https://review.typo3.org/58822
Reviewed-by: Richard Haeser <richard@maxserv.com>
Tested-by: Richard Haeser <richard@maxserv.com>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/core/Documentation/Changelog/9.5.x/Feature-86826-RecursiveRecordSitemap.rst [new file with mode: 0644]
typo3/sysext/seo/Classes/XmlSitemap/RecordsXmlSitemapDataProvider.php

diff --git a/typo3/sysext/core/Documentation/Changelog/9.5.x/Feature-86826-RecursiveRecordSitemap.rst b/typo3/sysext/core/Documentation/Changelog/9.5.x/Feature-86826-RecursiveRecordSitemap.rst
new file mode 100644 (file)
index 0000000..36e0cf4
--- /dev/null
@@ -0,0 +1,52 @@
+.. include:: ../../Includes.txt
+
+==========================================
+Feature: #86826 - Recursive record sitemap
+==========================================
+
+See :issue:`86826`
+
+Description
+===========
+
+The :php:`RecordsXmlSitemapDataProvider` supports now the configuration `recursive` to include
+records not only from provided list of page ids but also its subpages.
+
+
+Impact
+======
+
+A full example looks is:
+
+.. code-block:: typoscript
+
+  config {
+    xmlSitemap {
+        news {
+          provider = TYPO3\CMS\Seo\XmlSitemap\RecordsXmlSitemapDataProvider
+          config {
+            table = tx_news_domain_model_news
+            sortField = sorting
+            lastModifiedField = tstamp
+            pid = 26
+            recursive = 2
+            url {
+              pageId = 25
+              fieldToParameterMap {
+                uid = tx_news_pi1[news]
+              }
+
+              additionalGetParameters {
+                tx_news_pi1.controller = News
+                tx_news_pi1.action = detail
+              }
+
+              useCacheHash = 1
+            }
+          }
+        }
+      }
+    }
+  }
+
+.. index:: Frontend, ext:seo, NotScanned
\ No newline at end of file
index aca31fc..b0e4fab 100644 (file)
@@ -64,6 +64,18 @@ class RecordsXmlSitemapDataProvider extends AbstractXmlSitemapDataProvider
         $constraints = [];
 
         if (!empty($pids)) {
+            $recursiveLevel = isset($this->config['recursive']) ? (int)$this->config['recursive'] : 0;
+            if ($recursiveLevel) {
+                $newList = [];
+                foreach ($pids as $pid) {
+                    $list = $this->cObj->getTreeList($pid, $recursiveLevel);
+                    if ($list) {
+                        $newList = array_merge($newList, explode(',', $list));
+                    }
+                }
+                $pids = array_merge($pids, $newList);
+            }
+
             $constraints[] = $queryBuilder->expr()->in('pid', $pids);
         }