diff --git a/typo3/sysext/backend/Classes/View/PageLayoutView.php b/typo3/sysext/backend/Classes/View/PageLayoutView.php index 99d973077106..cce2ddcbcc57 100644 --- a/typo3/sysext/backend/Classes/View/PageLayoutView.php +++ b/typo3/sysext/backend/Classes/View/PageLayoutView.php @@ -3407,6 +3407,8 @@ protected function prepareQueryBuilder( $hookName = DatabaseRecordList::class; foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][$hookName]['buildQueryParameters'] ?? [] as $className) { + // @deprecated since TYPO3 v9, will be removed in TYPO3 v10, the modifyQuery hook should be used instead. + trigger_error('The hook ($GLOBALS[\'TYPO3_CONF_VARS\'][\'SC_OPTIONS\'][' . $hookName . '][\'buildQueryParameters\']) will be removed in TYPO3 v10, the modifyQuery hook should be used instead.', E_USER_DEPRECATED); $hookObject = GeneralUtility::makeInstance($className); if (method_exists($hookObject, 'buildQueryParametersPostProcess')) { $hookObject->buildQueryParametersPostProcess( @@ -3420,6 +3422,19 @@ protected function prepareQueryBuilder( ); } } + foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][PageLayoutView::class]['modifyQuery'] ?? [] as $className) { + $hookObject = GeneralUtility::makeInstance($className); + if (method_exists($hookObject, 'modifyQuery')) { + $hookObject->modifyQuery( + $parameters, + $table, + $pageId, + $additionalConstraints, + $fieldList, + $queryBuilder + ); + } + } // array_unique / array_filter used to eliminate empty and duplicate constraints // the array keys are eliminated by this as well to facilitate argument unpacking diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-83740-CleanupOfAbstractRecordListBreaksHook.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-83740-CleanupOfAbstractRecordListBreaksHook.rst new file mode 100644 index 000000000000..d19bfaae3cb0 --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-83740-CleanupOfAbstractRecordListBreaksHook.rst @@ -0,0 +1,38 @@ +.. include:: ../../Includes.txt + +=============================================================== +Deprecation: #83740 - Cleanup of AbstractRecordList breaks hook +=============================================================== + +See :issue:`83740` + +Description +=========== + +The hook `$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList']['buildQueryParameters']` +has been marked as deprecated. It was a hook to modify the current database query but used in multiple classes which +leads to some issues. For this reason, the old hook is now deprecated and will be removed in v10. + + +Impact +====== + +Registering a hook in `$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList']['buildQueryParameters']` will trigger a deprecation warning. + + +Affected installations +====================== + +Instances with extensions using a `$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList']['buildQueryParameters']`-hook + + +Migration +========= + +Two new hooks are available to achieve the same things. + +Please see: + +Feature-83740-CleanupOfAbstractRecordListBreaksHook.rst + +.. index:: Backend, Database, PHP-API, FullyScanned diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-83740-CleanupOfAbstractRecordListBreaksHook.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-83740-CleanupOfAbstractRecordListBreaksHook.rst new file mode 100644 index 000000000000..bfb4ce925b36 --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/master/Feature-83740-CleanupOfAbstractRecordListBreaksHook.rst @@ -0,0 +1,54 @@ +.. include:: ../../Includes.txt + +=========================================================== +Feature: #83740 - Cleanup of AbstractRecordList breaks hook +=========================================================== + +See :issue:`83740` + +Description +=========== + +A new hook in :php:`DatabaseRecordList` and :php:`PageLayoutView` allows modify the current database query. + +Register the hook via + +* php:`$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][\TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList::class]['modifyQuery']` +* php:`$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][\TYPO3\CMS\Backend\View\PageLayoutView::class]['modifyQuery']` + +in the extensions :file:`ext_localconf.php` file. + +Example +======= + +An example implementation could look like this: + +:file:`EXT:my_site/ext_localconf.php` + +.. code-block:: php + + $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][\TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList::class]['modifyQuery'][1313131313] = + \MyVendor\MySite\Hooks\DatabaseRecordListHook::class . '->modifyQuery'; + + +:file:`EXT:my_site/Classes/Hooks/DatabaseRecordListHook.php` + +.. code-block:: php + + namespace MyVendor\MySite\Hooks; + + class DatabaseRecordListHook + { + public function modifyQuery( + array $parameters, + string $table, + int $pageId, + array $additionalConstraints, + array $fieldList, + \TYPO3\CMS\Core\Database\Query\QueryBuilder $queryBuilder + ) { + // modify $queryBuilder + } + } + +.. index:: Backend, Database, PHP-API diff --git a/typo3/sysext/install/Configuration/ExtensionScanner/Php/ArrayDimensionMatcher.php b/typo3/sysext/install/Configuration/ExtensionScanner/Php/ArrayDimensionMatcher.php index 13cc1e58ea54..a514943823f8 100644 --- a/typo3/sysext/install/Configuration/ExtensionScanner/Php/ArrayDimensionMatcher.php +++ b/typo3/sysext/install/Configuration/ExtensionScanner/Php/ArrayDimensionMatcher.php @@ -144,4 +144,9 @@ 'Deprecation-83252-Link-tagSyntaxProcesssing.rst', ], ], + '$GLOBALS[\'TYPO3_CONF_VARS\'][\'SC_OPTIONS\'][\'TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList\'][\'buildQueryParameters\']' => [ + 'restFiles' => [ + 'Deprecation-83740-CleanupOfAbstractRecordListBreaksHook.rst', + ], + ], ]; diff --git a/typo3/sysext/recordlist/Classes/RecordList/AbstractDatabaseRecordList.php b/typo3/sysext/recordlist/Classes/RecordList/AbstractDatabaseRecordList.php index 00828ef9cc68..926ed98d367d 100644 --- a/typo3/sysext/recordlist/Classes/RecordList/AbstractDatabaseRecordList.php +++ b/typo3/sysext/recordlist/Classes/RecordList/AbstractDatabaseRecordList.php @@ -803,6 +803,8 @@ protected function prepareQueryBuilder( $hookName = DatabaseRecordList::class; if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][$hookName]['buildQueryParameters'])) { + // @deprecated since TYPO3 v9, will be removed in TYPO3 v10, the modifyQuery hook should be used instead. + trigger_error('The hook ($GLOBALS[\'TYPO3_CONF_VARS\'][\'SC_OPTIONS\'][' . $hookName . '][\'buildQueryParameters\']) will be removed in TYPO3 v10, the modifyQuery hook should be used instead.', E_USER_DEPRECATED); foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][$hookName]['buildQueryParameters'] as $className) { $hookObject = GeneralUtility::makeInstance($className); if (method_exists($hookObject, 'buildQueryParametersPostProcess')) { diff --git a/typo3/sysext/recordlist/Classes/RecordList/DatabaseRecordList.php b/typo3/sysext/recordlist/Classes/RecordList/DatabaseRecordList.php index b2fba7c00606..63424b36956c 100644 --- a/typo3/sysext/recordlist/Classes/RecordList/DatabaseRecordList.php +++ b/typo3/sysext/recordlist/Classes/RecordList/DatabaseRecordList.php @@ -3262,8 +3262,10 @@ protected function prepareQueryBuilder( ); } - $hookName = static::class; + $hookName = DatabaseRecordList::class; if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][$hookName]['buildQueryParameters'])) { + // @deprecated since TYPO3 v9, will be removed in TYPO3 v10, the modifyQuery hook should be used instead. + trigger_error('The hook ($GLOBALS[\'TYPO3_CONF_VARS\'][\'SC_OPTIONS\'][' . $hookName . '][\'buildQueryParameters\']) will be removed in TYPO3 v10, the modifyQuery hook should be used instead.', E_USER_DEPRECATED); foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][$hookName]['buildQueryParameters'] as $className) { $hookObject = GeneralUtility::makeInstance($className); if (method_exists($hookObject, 'buildQueryParametersPostProcess')) { @@ -3279,6 +3281,19 @@ protected function prepareQueryBuilder( } } } + foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][$hookName]['modifyQuery'] ?? [] as $className) { + $hookObject = GeneralUtility::makeInstance($className); + if (method_exists($hookObject, 'modifyQuery')) { + $hookObject->modifyQuery( + $parameters, + $table, + $pageId, + $additionalConstraints, + $fieldList, + $queryBuilder + ); + } + } // array_unique / array_filter used to eliminate empty and duplicate constraints // the array keys are eliminated by this as well to facilitate argument unpacking