[BUGFIX] Make RecordBrowser highlight selected record again 70/54370/18
authorStanislas Rolland <typo3@sjbr.ca>
Wed, 11 Oct 2017 21:54:27 +0000 (17:54 -0400)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Thu, 15 Mar 2018 12:43:43 +0000 (13:43 +0100)
When using the element browser wizard with a configured record link
handler, the record browser now highlights the currently linked
record again.

Resolves: #82739
Releases: master, 8.7
Change-Id: Iba47f18bf150bb4646729c6a5ecdae46b7d56754
Reviewed-on: https://review.typo3.org/54370
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
typo3/sysext/recordlist/Classes/RecordList/DatabaseRecordList.php

index e8188ec..195e283 100644 (file)
@@ -33,6 +33,8 @@ use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
 use TYPO3\CMS\Core\Database\ReferenceIndex;
 use TYPO3\CMS\Core\Imaging\Icon;
 use TYPO3\CMS\Core\Imaging\IconFactory;
+use TYPO3\CMS\Core\LinkHandling\Exception\UnknownLinkHandlerException;
+use TYPO3\CMS\Core\LinkHandling\LinkService;
 use TYPO3\CMS\Core\Localization\LanguageService;
 use TYPO3\CMS\Core\Log\LogManager;
 use TYPO3\CMS\Core\Messaging\FlashMessage;
@@ -585,11 +587,18 @@ class DatabaseRecordList
 
     /**
      * Override/add urlparameters in listUrl() method
-     * @var string[]
+     * @var mixed[]
      */
     protected $overrideUrlParameters = [];
 
     /**
+     * Current link: array with table names and uid
+     *
+     * @var array
+     */
+    protected $currentLink = [];
+
+    /**
      * Only used to render translated records, used in list module to show page translations
      *
      * @var bool
@@ -1376,6 +1385,14 @@ class DatabaseRecordList
             'title' => 'id=' . $row['uid'],
         ];
 
+        // Add active class to record of current link
+        if (
+            isset($this->currentLink['tableNames'])
+            && (int)$this->currentLink['uid'] === (int)$row['uid']
+            && GeneralUtility::inList($this->currentLink['tableNames'], $table)
+        ) {
+            $tagAttributes['class'][] = 'active';
+        }
         // Add special classes for first and last row
         if ($cc == 1 && $indent == 0) {
             $tagAttributes['class'][] = 'firstcol';
@@ -2885,6 +2902,20 @@ class DatabaseRecordList
             );
         }
 
+        // If there is a current link to a record, set the current link uid and get the table name from the link handler configuration
+        $currentLinkValue = isset($this->overrideUrlParameters['P']['currentValue']) ? trim($this->overrideUrlParameters['P']['currentValue']) : '';
+        if ($currentLinkValue) {
+            $linkService = GeneralUtility::makeInstance(LinkService::class);
+            try {
+                $currentLinkParts = $linkService->resolve($currentLinkValue);
+                if ($currentLinkParts['type'] === 'record' && isset($currentLinkParts['identifier'])) {
+                    $this->currentLink['tableNames'] = $this->tableList;
+                    $this->currentLink['uid'] = (int)$currentLinkParts['uid'];
+                }
+            } catch (UnknownLinkHandlerException $e) {
+            }
+        }
+
         // $table might be NULL at this point in the code. As the expressionBuilder
         // is used to limit returned records based on the page permissions and the
         // uid field of the pages it can hardcoded to work on the pages table.
@@ -3837,6 +3868,10 @@ class DatabaseRecordList
      */
     public function setOverrideUrlParameters(array $urlParameters)
     {
+        $currentUrlParameter = GeneralUtility::_GP('curUrl');
+        if (isset($currentUrlParameter['url'])) {
+            $urlParameters['P']['currentValue'] = $currentUrlParameter['url'];
+        }
         $this->overrideUrlParameters = $urlParameters;
     }