From c596fa3c399f0c81494e256df9cd101a7d81eecd Mon Sep 17 00:00:00 2001
From: Georg Ringer <georg.ringer@gmail.com>
Date: Wed, 1 May 2024 10:05:33 +0200
Subject: [PATCH] [FEATURE] Make insert record available #508

---
 Classes/Controller/AddressController.php  |  8 +++++++-
 Configuration/TypoScript/setup.typoscript | 17 +++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/Classes/Controller/AddressController.php b/Classes/Controller/AddressController.php
index 020d9123..c8ef1eed 100755
--- a/Classes/Controller/AddressController.php
+++ b/Classes/Controller/AddressController.php
@@ -27,6 +27,7 @@
 use TYPO3\CMS\Extbase\Pagination\QueryResultPaginator;
 use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
 use TYPO3\CMS\Extbase\Reflection\ObjectAccess;
+use TYPO3\CMS\Extbase\Utility\DebuggerUtility;
 
 /**
  * AddressController
@@ -74,8 +75,13 @@ public function showAction(Address $address = null)
      */
     public function listAction(?array $override = [])
     {
+        $contentData = $this->configurationManager->getContentObject()->data;
         $demand = $this->createDemandFromSettings();
 
+        if (isset($contentData['first_name'], $contentData['birthday']) && (int)($this->settings['insertRecord'] ?? 0) === 1) {
+            $demand->setSingleRecords((string)$contentData['uid']);
+        }
+
         if (!empty($override) && $this->settings['allowOverride']) {
             $this->overrideDemand($demand, $override);
         }
@@ -98,7 +104,7 @@ public function listAction(?array $override = [])
         $this->view->assignMultiple([
             'demand' => $demand,
             'addresses' => $addresses,
-            'contentObjectData' => $this->configurationManager->getContentObject()->data,
+            'contentObjectData' => $contentData,
         ]);
 
         CacheUtility::addCacheTagsByAddressRecords(
diff --git a/Configuration/TypoScript/setup.typoscript b/Configuration/TypoScript/setup.typoscript
index acbd6f98..31269dd0 100755
--- a/Configuration/TypoScript/setup.typoscript
+++ b/Configuration/TypoScript/setup.typoscript
@@ -85,3 +85,20 @@ plugin.tx_ttaddress {
         }
     }
 }
+
+
+# Rendering of tt_address, displayed by "Insert Record" content element
+tt_content.shortcut.variables.shortcuts.tables := addToList(tt_address)
+tt_content.shortcut.variables.shortcuts.conf.tt_address = USER
+tt_content.shortcut.variables.shortcuts.conf.tt_address {
+    userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
+    extensionName = TtAddress
+    pluginName = ListView
+    vendorName = FriendsOfTYPO3
+
+    settings =< plugin.tx_ttaddress.settings
+    settings {
+        displayMode = single
+        insertRecord = 1
+    }
+}
\ No newline at end of file