[TASK] Migrate Recordlist hook to TYPO3 9 LTS 17/58617/3
authorStanislas Rolland <typo3@sjbr.ca>
Thu, 11 Oct 2018 20:45:10 +0000 (16:45 -0400)
committerStanislas Rolland <typo3@sjbr.ca>
Thu, 11 Oct 2018 20:49:34 +0000 (22:49 +0200)
BuildQueryParameters becomes ModifyQuery.

Change-Id: I5a6eb48e726e74a18e165dd67b49a00b03ac63a9
Resolves: #86633
Reviewed-on: https://review.typo3.org/58617
Reviewed-by: Stanislas Rolland <typo3@sjbr.ca>
Tested-by: Stanislas Rolland <typo3@sjbr.ca>
ChangeLog
Classes/Hook/Backend/Recordlist/ModifyQuery.php [new file with mode: 0644]
ext_localconf.php

index 7b3901e..ace3d29 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2018-10-11  Stanislas Rolland  <typo3(arobas)sjbr.ca>
+
+       * Resolves #86633: Migrate Recordlist hook to TYPO3 9 LTS
+
 2018-10-9  Stanislas Rolland  <typo3(arobas)sjbr.ca>
 
        * Resolves #86608: Remove support for TYPO3 7 LTS - Thanks to Tomas Norre Mikkelsen
diff --git a/Classes/Hook/Backend/Recordlist/ModifyQuery.php b/Classes/Hook/Backend/Recordlist/ModifyQuery.php
new file mode 100644 (file)
index 0000000..4b5e364
--- /dev/null
@@ -0,0 +1,66 @@
+<?php
+namespace SJBR\StaticInfoTables\Hook\Backend\Recordlist;
+
+/*
+ *  Copyright notice
+ *
+ *  (c) 2018 Stanislas Rolland <typo3(arobas)sjbr.ca>
+ *  All rights reserved
+ *
+ *  This script is part of the Typo3 project. The Typo3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ */
+
+use TYPO3\CMS\Core\Database\Query\QueryBuilder;
+use TYPO3\CMS\Core\Database\Query\QueryHelper;
+use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
+/**
+ * Order records according to language field of current language
+ */
+class ModifyQuery
+{
+       /**
+        * Specify records order
+        *
+        * @param array $parameters
+        * @param string $table
+        * @param int $pageId
+        * @param string $additionalConstraints
+        * @param string $fieldList
+        * @param QueryBuilder $queryBuilder
+        * @return void
+        */
+       public function modifyQuery(&$parameters, $table, $pageId, $additionalConstraints, $fieldList, QueryBuilder $queryBuilder)
+       {
+               if (in_array($table, array_keys($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['static_info_tables']['tables']))) {
+                       $lang = substr(strtolower($this->getLanguageService()->lang), 0, 2);
+                       if (ExtensionManagementUtility::isLoaded('static_info_tables_' . $lang)) {
+                               $orderBy = str_replace('##', $lang, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['static_info_tables']['tables'][$table]['label_fields'][0]);
+                               $orderByFields = QueryHelper::parseOrderBy((string)$orderBy);
+                               foreach ($orderByFields as $fieldNameAndSorting) {
+                                       list($fieldName, $sorting) = $fieldNameAndSorting;
+                                       $queryBuilder->addOrderBy($fieldName, $sorting);
+                               }
+                       }
+               }
+       }
+
+       protected function getLanguageService()
+       {
+               return $GLOBALS['LANG'];
+       }
+}
\ No newline at end of file
index 59f4f12..be7413c 100644 (file)
@@ -5,7 +5,11 @@ call_user_func(
     function($extKey)
     {
                // Get the extensions's configuration
-               $extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$extKey]);
+               if (class_exists(\TYPO3\CMS\Core\Configuration\ExtensionConfiguration::class)) {
+                       $extConf = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Configuration\ExtensionConfiguration::class)->get($extKey);
+               } else {
+                       $extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$extKey]);
+               }
                // Register cache static_info_tables
                if (!is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'][$extKey])) {
                        $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'][$extKey] = [];
@@ -81,12 +85,16 @@ call_user_func(
                $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$extKey]['enableManager'] = isset($extConf['enableManager']) ? $extConf['enableManager'] : '0';
                // Make the extension version and constraints available when creating language packs and to other extensions
                $emConfUtility = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extensionmanager\Utility\EmConfUtility::class);
-               $emConf = $emConfUtility->includeEmConf(['key' => $extKey, 'siteRelPath' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($extKey)]);
+               $emConf = $emConfUtility->includeEmConf(['key' => $extKey, 'siteRelPath' =>  \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($extKey))]);
                $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$extKey]['version'] = $emConf[$extKey]['version'];
                $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$extKey]['constraints'] = $emConf[$extKey]['constraints'];
                // Configure translation of suggestions labels
                \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig('<INCLUDE_TYPOSCRIPT: source="FILE:EXT:' . $extKey . '/Configuration/PageTSconfig/Suggest.tsconfig">');
-               $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][\TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList::class]['buildQueryParameters'][] = \SJBR\StaticInfoTables\Hook\Backend\Recordlist\BuildQueryParameters::class;
+               if (\TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionNumberToInteger(\TYPO3\CMS\Core\Utility\VersionNumberUtility::getNumericTypo3Version()) < 9000000) {
+                       $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][\TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList::class]['buildQueryParameters'][] = \SJBR\StaticInfoTables\Hook\Backend\Recordlist\BuildQueryParameters::class;
+               } else {
+                       $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][\TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList::class]['modifyQuery'][] = \SJBR\StaticInfoTables\Hook\Backend\Recordlist\ModifyQuery::class;
+               }
        },
        'static_info_tables'
 );
\ No newline at end of file