From 1692a100825d553ef13e0f59ee89a4cb36924032 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=B6rg=20B=C3=B6sche?= <typo3@joergboesche.de>
Date: Thu, 10 Aug 2017 13:32:20 +0200
Subject: [PATCH] [FEATURE] Exclude doktypes in path of search result

The search result has a path with the pagetree structure.
It must be possible to exclude doktypes from the path.

Releases: master
Resolves: #82070
Change-Id: I15d6bb0765aa237ab86cb75e6ffff0c26d8f504d
Reviewed-on: https://review.typo3.org/53671
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Reviewed-by: Frans Saris <franssaris@gmail.com>
Tested-by: Frans Saris <franssaris@gmail.com>
Reviewed-by: Tobi Kretschmann <tobi@tobishome.de>
Reviewed-by: Jan Helke <typo3@helke.de>
Tested-by: Jan Helke <typo3@helke.de>
---
 ...re-82070-ExcludeDoktypesInSearchResult.rst | 60 +++++++++++++++++++
 .../Classes/Controller/SearchController.php   |  8 +++
 .../Configuration/TypoScript/setup.txt        |  1 +
 .../Configuration/TypoScript/Index.rst        | 27 +++++++++
 4 files changed, 96 insertions(+)
 create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Feature-82070-ExcludeDoktypesInSearchResult.rst

diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-82070-ExcludeDoktypesInSearchResult.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-82070-ExcludeDoktypesInSearchResult.rst
new file mode 100644
index 000000000000..1dd1851ef52b
--- /dev/null
+++ b/typo3/sysext/core/Documentation/Changelog/master/Feature-82070-ExcludeDoktypesInSearchResult.rst
@@ -0,0 +1,60 @@
+.. include:: ../../Includes.txt
+
+============================================================================
+Feature: #82070 - Exclude doktypes in path of search result (indexed_search)
+============================================================================
+
+See :issue:`82070`
+
+Description
+===========
+After submitting the search form in Indexed Search, the search results are displayed.
+Each search result displays a "path" and contains the page tree structure.
+In the structure, system folders can be used, which actually can't be excluded when the path is rendered.
+Similar to "hide in menu" or "RealUrl exclude from path segment", there should be a configuration to exclude doktypes
+from the path render business logic.
+
+Page tree structure:
+[SysFolder] Footer -> [SysFolder] Navigation -> [Page] Imprint
+
+Output in Indexed Search without :php:`pathExcludeDoktypes` settings:
+:php:`/Footer/Navigation/Imprint`
+
+Output in Indexed Search with :php:`pathExcludeDoktypes` settings:
+:php:`/Imprint`
+
+
+Examples
+~~~~~~~~
+
+Exclude single doktype
+**********************
+
+sys_folder (doktype: 254)
+
+.. code-block:: typoscript
+
+    plugin.tx_indexedsearch {
+        settings {
+            results {
+                pathExcludeDoktypes = 254
+            }
+        }
+    }
+
+Exclude multiple doktypes
+*************************
+
+sys_folder (doktype: 254) and shortcuts (doktype:4)
+
+.. code-block:: typoscript
+
+    plugin.tx_indexedsearch {
+        settings {
+            results {
+                pathExcludeDoktypes = 254,4
+            }
+        }
+    }
+
+.. index:: Frontend, ext:indexed_search, TypoScript
diff --git a/typo3/sysext/indexed_search/Classes/Controller/SearchController.php b/typo3/sysext/indexed_search/Classes/Controller/SearchController.php
index 56012789a64a..2711e4ee3094 100644
--- a/typo3/sysext/indexed_search/Classes/Controller/SearchController.php
+++ b/typo3/sysext/indexed_search/Classes/Controller/SearchController.php
@@ -1408,10 +1408,18 @@ class SearchController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControlle
             $path = '';
             $pageCount = count($rl);
             if (is_array($rl) && !empty($rl)) {
+                $excludeDoktypesFromPath = GeneralUtility::trimExplode(
+                    ',',
+                    $this->settings['results']['pathExcludeDoktypes'] ?? '',
+                    true
+                );
                 $breadcrumbWrap = isset($this->settings['breadcrumbWrap']) ? $this->settings['breadcrumbWrap'] : '/';
                 $breadcrumbWraps = GeneralUtility::makeInstance(TypoScriptService::class)
                     ->explodeConfigurationForOptionSplit(['wrap' => $breadcrumbWrap], $pageCount);
                 foreach ($rl as $k => $v) {
+                    if (in_array($v['doktype'], $excludeDoktypesFromPath, false)) {
+                        continue;
+                    }
                     // Check fe_user
                     if ($v['fe_group'] && ($v['uid'] == $id || $v['extendToSubpages'])) {
                         $this->requiredFrontendUsergroups[$id][] = $v['fe_group'];
diff --git a/typo3/sysext/indexed_search/Configuration/TypoScript/setup.txt b/typo3/sysext/indexed_search/Configuration/TypoScript/setup.txt
index 92bbbdeef639..e0e1dec11ed9 100644
--- a/typo3/sysext/indexed_search/Configuration/TypoScript/setup.txt
+++ b/typo3/sysext/indexed_search/Configuration/TypoScript/setup.txt
@@ -49,6 +49,7 @@ plugin.tx_indexedsearch {
 			markupSW_postPreLgd_offset = 5
 			markupSW_divider = ...
 			markupSW_divider.noTrimWrap = | | |
+			pathExcludeDoktypes =
 		}
 
 		# Blinding of option-selectors / values in these (advanced search)
diff --git a/typo3/sysext/indexed_search/Documentation/Configuration/TypoScript/Index.rst b/typo3/sysext/indexed_search/Documentation/Configuration/TypoScript/Index.rst
index ef8073c3c640..cee60334b999 100644
--- a/typo3/sysext/indexed_search/Documentation/Configuration/TypoScript/Index.rst
+++ b/typo3/sysext/indexed_search/Documentation/Configuration/TypoScript/Index.rst
@@ -603,6 +603,33 @@ results\_markupSW_divider
          Divider for highlighted searchwords in the summary
          Defaults to "..."
 
+.. _results-pathExcludeDoktypes:
+
+results\_pathExcludeDoktypes
+""""""""""""""""""""""""""""
+
+.. container:: table-row
+
+   Property
+         results\_pathExcludeDoktypes
+
+   Data type
+         string
+
+   Description
+         Excludes doktypes in path.
+         Defaults to ""
+
+         **Example:**
+         pathExcludeDoktypes = 254
+         Exclude sys_folder (doktype: 254) in path for result.
+
+         "/Footer(254)/Navi(254)/Imprint(1)" -> "/Imprint".
+
+         pathExcludeDoktypes = 254,4
+         Exclude sys_folder (doktype: 254) and shortcuts (doktype:4) in path for result.
+         "/About-Us(254)/Company(4)/Germany(1)" -> "/Germany".
+
 
 .. _linkSectionTitles-stdWrap:
 
-- 
GitLab