From d15d1aef2390b94bcc828a3b6c957597a3ddd084 Mon Sep 17 00:00:00 2001
From: Christoph Schwob <christoph@websailor.at>
Date: Mon, 7 Nov 2022 12:41:33 +0100
Subject: [PATCH] [FEATURE] Add a description field to redirects
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Add a description field also for redirects, which
could be used to add notes for further handling of
the correpsonding redirect. This follows the same
logic like for other record types.

Resolves: #99011
Releases: main
Change-Id: I216eca8e72b9bf825ad9542997ec603f01ddc879
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/76456
Tested-by: Stefan Bürk <stefan@buerk.tech>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Stefan Bürk <stefan@buerk.tech>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
---
 ...re-99011-AllowDescriptionsForRedirects.rst | 29 +++++++++++++++++++
 .../Classes/Service/RedirectCacheService.php  |  2 ++
 .../Configuration/TCA/sys_redirect.php        | 13 ++++++++-
 3 files changed, 43 insertions(+), 1 deletion(-)
 create mode 100644 typo3/sysext/core/Documentation/Changelog/12.1/Feature-99011-AllowDescriptionsForRedirects.rst

diff --git a/typo3/sysext/core/Documentation/Changelog/12.1/Feature-99011-AllowDescriptionsForRedirects.rst b/typo3/sysext/core/Documentation/Changelog/12.1/Feature-99011-AllowDescriptionsForRedirects.rst
new file mode 100644
index 000000000000..396242409101
--- /dev/null
+++ b/typo3/sysext/core/Documentation/Changelog/12.1/Feature-99011-AllowDescriptionsForRedirects.rst
@@ -0,0 +1,29 @@
+.. include:: /Includes.rst.txt
+
+.. _feature-99011-1667944274:
+
+==================================================
+Feature: #99011 - Allow descriptions for redirects
+==================================================
+
+See :issue:`99011`
+
+Description
+===========
+
+A new field :php:`description` has been added to the :sql:`sys_redirects` table.
+
+In the backend edit form, the new field is located under the :guilabel:`Notes`
+tab. It can be used to add context to the corresponding redirect. Since the
+field is defined as the records' :php:`descriptionColumn`, the added
+information is also displayed in the "Record information" info box
+above the edit form, like known form e.g. content elements or pages.
+
+Impact
+======
+
+It's now possible to add additional information to a redirect
+using the new description field, whose value is also displayed
+in the corresponding backend edit form.
+
+.. index:: Database, TCA, Backend
diff --git a/typo3/sysext/redirects/Classes/Service/RedirectCacheService.php b/typo3/sysext/redirects/Classes/Service/RedirectCacheService.php
index 3bb8e5c7c92b..81c8fedd2daf 100644
--- a/typo3/sysext/redirects/Classes/Service/RedirectCacheService.php
+++ b/typo3/sysext/redirects/Classes/Service/RedirectCacheService.php
@@ -85,6 +85,8 @@ class RedirectCacheService
         }
         $statement = $queryBuilder->executeQuery();
         while ($row = $statement->fetchAssociative()) {
+            // Field "description" is not needed for FE redirect handling. Don't add it to cache.
+            unset($row['description']);
             if ($row['is_regexp']) {
                 $redirects['regexp'][$row['source_path']][$row['uid']] = $row;
             } elseif ($row['respect_query_parameters']) {
diff --git a/typo3/sysext/redirects/Configuration/TCA/sys_redirect.php b/typo3/sysext/redirects/Configuration/TCA/sys_redirect.php
index 969ccb78af89..94dc66b35115 100644
--- a/typo3/sysext/redirects/Configuration/TCA/sys_redirect.php
+++ b/typo3/sysext/redirects/Configuration/TCA/sys_redirect.php
@@ -3,6 +3,7 @@
 return [
     'ctrl' => [
         'title' => 'LLL:EXT:redirects/Resources/Private/Language/locallang_db.xlf:sys_redirect',
+        'descriptionColumn' => 'description',
         'label' => 'source_host',
         'label_alt' => 'source_path',
         'label_alt_force' => true,
@@ -32,7 +33,8 @@ return [
             'showitem' => '
                 --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:general, --palette--;;source, --palette--;;targetdetails, protected, creation_type,
                 --div--;LLL:EXT:redirects/Resources/Private/Language/locallang_db.xlf:tabs.redirectCount, disable_hitcount, hitcount, lasthiton, createdon,
-                --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:access, --palette--;;visibility',
+                --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:access, --palette--;;visibility,
+                --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:notes, description',
         ],
     ],
     'palettes' => [
@@ -272,5 +274,14 @@ return [
                 'default' => 1,
             ],
         ],
+        'description' => [
+            'exclude' => true,
+            'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.description',
+            'config' => [
+                'type' => 'text',
+                'rows' => 5,
+                'cols' => 40,
+            ],
+        ],
     ],
 ];
-- 
GitLab