From ebb0593080a3d4ba7a04388c3347907bb1f685d1 Mon Sep 17 00:00:00 2001 From: Benni Mack <benni@typo3.org> Date: Wed, 8 Sep 2021 08:28:34 +0200 Subject: [PATCH] [TASK] Deprecate TSFE->ATagParams The TypoScriptFrontendController holds a property called "ATagParams". Its value is a copy of $TSFE->config[config][ATagParams]. The information can be retrieved from the config array, just like all other things are loaded there, as the usages of this property are rather low. In addition cObj->getTagParams' 2nd argument "addGlobal" which is always set to true, is marked as deprecated as well. Resolves: #95219 Releases: master Change-Id: I39a12bc717bff8bb3c50af7eaab726cf7b2f4d7a Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/70965 Tested-by: core-ci <typo3@b13.com> Tested-by: Christian Kuhn <lolli@schwarzbu.ch> Tested-by: Jochen <rothjochen@gmail.com> Tested-by: Oliver Bartsch <bo@cedev.de> Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch> Reviewed-by: Jochen <rothjochen@gmail.com> Reviewed-by: Oliver Bartsch <bo@cedev.de> --- .../PublicPropertyDeprecationTrait.php | 5 +- ...ypoScriptFrontendController-ATagParams.rst | 53 +++++++++++++++++++ .../ContentObject/ContentObjectRenderer.php | 15 ++++-- .../TypoScriptFrontendController.php | 12 ++++- .../ContentObjectRendererTest.php | 4 +- .../Php/MethodArgumentDroppedMatcher.php | 6 +++ .../Php/PropertyPublicMatcher.php | 5 ++ 7 files changed, 89 insertions(+), 11 deletions(-) create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Deprecation-95219-TypoScriptFrontendController-ATagParams.rst diff --git a/typo3/sysext/core/Classes/Compatibility/PublicPropertyDeprecationTrait.php b/typo3/sysext/core/Classes/Compatibility/PublicPropertyDeprecationTrait.php index ea22cf2d176e..c2bd5e4d51ac 100644 --- a/typo3/sysext/core/Classes/Compatibility/PublicPropertyDeprecationTrait.php +++ b/typo3/sysext/core/Classes/Compatibility/PublicPropertyDeprecationTrait.php @@ -42,10 +42,9 @@ namespace TYPO3\CMS\Core\Compatibility; * use PublicPropertyDeprecationTrait; * * /** - * * List previously publically accessible variables - * * @var array + * * List previously publicly accessible variables * *... - * private $deprecatedPublicProperties = [ + * private array $deprecatedPublicProperties = [ * 'myProperty' => 'Using myProperty is deprecated and will not be possible anymore in TYPO3 v10.0. Use getMyProperty() instead.' * ]; * diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-95219-TypoScriptFrontendController-ATagParams.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-95219-TypoScriptFrontendController-ATagParams.rst new file mode 100644 index 000000000000..1f73f1a572f3 --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-95219-TypoScriptFrontendController-ATagParams.rst @@ -0,0 +1,53 @@ +.. include:: ../../Includes.txt + +============================================================== +Deprecation: #95219 - TypoScriptFrontendController->ATagParams +============================================================== + +See :issue:`95219` + +Description +=========== + +The public property :php:`TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->ATagParams` +has been marked as deprecated. + +It was used in the past as a copy of the value +:php:`TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->config[config][ATagParams]`, +which should be used instead. + +There is no need to use such a (less prominent) configuration option in a +separate public property, as it needs to be kept in sync with the +actual configuration option. + +The second argument of the related method +:php:`TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer->getATagParams()` +called :php:`$addGlobal` is also marked as deprecated, and will have no effect +anymore in TYPO3 v12. + +Impact +====== + +Accessing, setting or writing this property will trigger a PHP deprecation +message. + +Calling :php:`TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer->getATagParams()` +with a second argument set to false will trigger a PHP deprecation message +as well. + + +Affected Installations +====================== + +TYPO3 installations with third-party-extensions accessing, or +writing this property directly within PHP, or calling :php:`getATagParams()` +directly, which is highly unlikely. + + +Migration +========= + +All calls of :php:`$GLOBALS['TSFE']->ATagParams` can be replaced +with :php:`$GLOBALS['TSFE']->config['config']['ATagParams'] ?? ''`. + +.. index:: Frontend, PHP-API, TypoScript, FullyScanned, ext:frontend diff --git a/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php b/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php index 9dc5a9dd2698..d263621f703c 100644 --- a/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php +++ b/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php @@ -1149,7 +1149,7 @@ class ContentObjectRenderer implements LoggerAwareInterface $a1 = sprintf( '<a %s%s>', GeneralUtility::implodeAttributes($attrs, true), - $this->getTypoScriptFrontendController()->ATagParams + trim($this->getTypoScriptFrontendController()->config['config']['ATagParams'] ?? '') ? ' ' . trim($this->getTypoScriptFrontendController()->config['config']['ATagParams']) : '' ); $a2 = '</a>'; $this->addDefaultFrontendJavaScript(); @@ -1188,15 +1188,20 @@ class ContentObjectRenderer implements LoggerAwareInterface * Uses the ATagParams property. * * @param array $conf TypoScript configuration properties - * @param bool|int $addGlobal If set, will add the global config.ATagParams to the link + * @param bool|int|null $addGlobal If set, will add the global config.ATagParams to the link. @deprecated will be removed in TYPO3 v12.0. * @return string String containing the parameters to the A tag (if non empty, with a leading space) * @see typolink() */ - public function getATagParams($conf, $addGlobal = 1) + public function getATagParams($conf, $addGlobal = null) { $aTagParams = ' ' . $this->stdWrapValue('ATagParams', $conf ?? []); - if ($addGlobal) { - $globalParams = $this->getTypoScriptFrontendController()->ATagParams ?? ''; + if ($addGlobal !== null) { + trigger_error('Setting the second argument $addGlobal of $cObj->getATagParams will have no effect in TYPO3 v12.0 anymore.', E_USER_DEPRECATED); + } + // Add the global config.ATagParams if $addGlobal is NULL (default) or set to TRUE. + // @deprecated The if clause can be removed in v12 + if ($addGlobal === null || $addGlobal) { + $globalParams = trim($this->getTypoScriptFrontendController()->config['config']['ATagParams'] ?? ''); $aTagParams = ' ' . trim($globalParams . $aTagParams); } // Extend params diff --git a/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php b/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php index 5647c1c78c5d..79448707b09a 100644 --- a/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php +++ b/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php @@ -24,6 +24,7 @@ use TYPO3\CMS\Backend\FrontendBackendUserAuthentication; use TYPO3\CMS\Core\Cache\CacheManager; use TYPO3\CMS\Core\Charset\CharsetConverter; use TYPO3\CMS\Core\Charset\UnknownCharsetException; +use TYPO3\CMS\Core\Compatibility\PublicPropertyDeprecationTrait; use TYPO3\CMS\Core\Configuration\Loader\PageTsConfigLoader; use TYPO3\CMS\Core\Configuration\Parser\PageTsConfigParser; use TYPO3\CMS\Core\Context\Context; @@ -97,6 +98,13 @@ use TYPO3\CMS\Frontend\Resource\FilePathSanitizer; class TypoScriptFrontendController implements LoggerAwareInterface { use LoggerAwareTrait; + use PublicPropertyDeprecationTrait; + /** + * List previously publicly accessible variables + */ + private array $deprecatedPublicProperties = [ + 'ATagParams' => 'Using ATagParams will not be possible anymore in TYPO3 v12.0. Use TSFE->config[config][ATagParams] instead.' + ]; /** * The page id (int) @@ -371,8 +379,9 @@ class TypoScriptFrontendController implements LoggerAwareInterface /** * <A>-tag parameters * @var string + * @deprecated will be removed in TYPO3 v12.0. Use TSFE->config[config][ATagParams] directly. */ - public $ATagParams = ''; + protected $ATagParams = ''; /** * Search word regex, calculated if there has been search-words send. This is @@ -2478,6 +2487,7 @@ class TypoScriptFrontendController implements LoggerAwareInterface $this->absRefPrefix = GeneralUtility::getIndpEnv('TYPO3_SITE_PATH'); } } + // @deprecated. This line can be removed with TYPO3 v12.0. $this->ATagParams = trim($this->config['config']['ATagParams'] ?? '') ? ' ' . trim($this->config['config']['ATagParams']) : ''; $this->initializeSearchWordData($request->getParsedBody()['sword_list'] ?? $request->getQueryParams()['sword_list'] ?? null); // linkVars diff --git a/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php b/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php index b6db163c4b18..738cac3b2cc1 100644 --- a/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php +++ b/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php @@ -1746,7 +1746,7 @@ class ContentObjectRendererTest extends UnitTestCase */ public function aTagParamsHaveSpaceBetweenLocalAndGlobalParams(): void { - $GLOBALS['TSFE']->ATagParams = 'data-global="dataglobal"'; + $GLOBALS['TSFE']->config['config']['ATagParams'] = 'data-global="dataglobal"'; $aTagParams = $this->subject->getATagParams(['ATagParams' => 'data-test="testdata"']); self::assertEquals(' data-global="dataglobal" data-test="testdata"', $aTagParams); } @@ -1757,7 +1757,7 @@ class ContentObjectRendererTest extends UnitTestCase public function aTagParamsHasNoLeadingSpaceIfEmpty(): void { // make sure global ATagParams are empty - $GLOBALS['TSFE']->ATagParams = ''; + $GLOBALS['TSFE']->config['config']['ATagParams'] = ''; $aTagParams = $this->subject->getATagParams(['ATagParams' => '']); self::assertEquals('', $aTagParams); } diff --git a/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodArgumentDroppedMatcher.php b/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodArgumentDroppedMatcher.php index 0edbf17f9327..f19807b94be2 100644 --- a/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodArgumentDroppedMatcher.php +++ b/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodArgumentDroppedMatcher.php @@ -309,4 +309,10 @@ return [ 'Deprecation-95062-SkipSortingArgumentOfRelationHandler-writeForeignField.rst', ], ], + 'TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer->getATagParams' => [ + 'maximumNumberOfArguments' => 1, + 'restFiles' => [ + 'Deprecation-95219-TypoScriptFrontendController-ATagParams.rst', + ], + ], ]; diff --git a/typo3/sysext/install/Configuration/ExtensionScanner/Php/PropertyPublicMatcher.php b/typo3/sysext/install/Configuration/ExtensionScanner/Php/PropertyPublicMatcher.php index 058a902c5b51..a93c25d7ecac 100644 --- a/typo3/sysext/install/Configuration/ExtensionScanner/Php/PropertyPublicMatcher.php +++ b/typo3/sysext/install/Configuration/ExtensionScanner/Php/PropertyPublicMatcher.php @@ -915,4 +915,9 @@ return [ 'Deprecation-95139-ExtbaseControllerContext.rst', ], ], + 'TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->ATagParams' => [ + 'restFiles' => [ + 'Deprecation-95219-TypoScriptFrontendController-ATagParams.rst', + ], + ], ]; -- GitLab