[TASK] Deprecate f:base ViewHelper
authorChristian Kuhn <lolli@schwarzbu.ch>
Fri, 28 May 2021 19:37:21 +0000 (21:37 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sun, 30 May 2021 17:35:32 +0000 (19:35 +0200)
The BaseViewHelper which renders a base tag is kinda
useless in our scope: Fluid based rendering typically
takes care of markup within body tag, but base must
be in head.
In frontend, a base tag is thus almost always set using
TypoScript config.baseURL, ending up in PageRenderer.
The backend does stuff like this on a different level,
usually ending up in the PageRenderer as well.
Even with HTML mails, a base tag is uncommon and would
usually - at least in the frontend - again render via
PageRenderer.
The patch deprecates BaseViewHelper.

Resolves: #94227
Releases: master
Change-Id: I7029dd609ca1f0aa1057b67380c7bd3a46b7ed09
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/69315
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Simon Gilli <typo3@gilbertsoft.org>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Simon Gilli <typo3@gilbertsoft.org>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/core/Documentation/Changelog/master/Deprecation-94227-FbaseViewHelper.rst [new file with mode: 0644]
typo3/sysext/fluid/Classes/ViewHelpers/BaseViewHelper.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/BaseViewHelperTest.php [deleted file]
typo3/sysext/fluid/Tests/UnitDeprecated/ViewHelpers/BaseViewHelperTest.php [new file with mode: 0644]

diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-94227-FbaseViewHelper.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-94227-FbaseViewHelper.rst
new file mode 100644 (file)
index 0000000..595adc8
--- /dev/null
@@ -0,0 +1,40 @@
+.. include:: ../../Includes.txt
+
+=======================================
+Deprecation: #94227 - f:base ViewHelper
+=======================================
+
+See :issue:`94227`
+
+Description
+===========
+
+The :html:`<f:base>`  ViewHelper isn't suitable in almost all use cases
+and has been deprecated: In most cases the :php:`PageRenderer` takes care of the
+main :html:`<head>` markup, directly, or indirectly via TypoScript :html:`config.baseURL`.
+
+
+Impact
+======
+
+Using the view helper in fluid templates will log a deprecation warning
+and the view helper will be dropped with v12.
+
+
+Affected Installations
+======================
+
+The limited use of the view helper likely leads to little usage numbers.
+Searching extensions for the string html:`<f:base>` should
+reveal any usages.
+
+
+Migration
+=========
+
+The easiest solution is to simply copy PHP class
+:php:`TYPO3\CMS\Fluid\ViewHelpers\BaseViewHelper` to the consuming extension,
+giving the view helper a happy life in an extension specific namespace.
+
+
+.. index:: Fluid, NotScanned, ext:fluid
index 0ed741f..53ccd9d 100644 (file)
@@ -40,8 +40,7 @@ use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
  *
  * Depending on your domain.
  *
- * @todo Deprecate this VH: In FE a base tag is set via TS config.baseURL to head, this
- *       VH would most likely add it as useless body tag, and BE does not need this VH.
+ * @deprecated since v11, will be removed in v12.
  */
 class BaseViewHelper extends AbstractViewHelper
 {
@@ -68,6 +67,7 @@ class BaseViewHelper extends AbstractViewHelper
      */
     public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
     {
+        trigger_error(__CLASS__ . ' will be removed in TYPO3 v12.', E_USER_DEPRECATED);
         $request = static::getRequest();
         /** @var NormalizedParams $normalizedParams */
         $normalizedParams = $request->getAttribute('normalizedParams');
diff --git a/typo3/sysext/fluid/Tests/Unit/ViewHelpers/BaseViewHelperTest.php b/typo3/sysext/fluid/Tests/Unit/ViewHelpers/BaseViewHelperTest.php
deleted file mode 100644 (file)
index 8dff4c1..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-<?php
-
-/*
- * This file is part of the TYPO3 CMS project.
- *
- * It is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License, either version 2
- * of the License, or any later version.
- *
- * For the full copyright and license information, please read the
- * LICENSE.txt file that was distributed with this source code.
- *
- * The TYPO3 project - inspiring people to share!
- */
-
-namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers;
-
-use Prophecy\Prophecy\ObjectProphecy;
-use Psr\Http\Message\ServerRequestInterface;
-use TYPO3\CMS\Core\Core\SystemEnvironmentBuilder;
-use TYPO3\CMS\Core\Http\NormalizedParams;
-use TYPO3\CMS\Fluid\ViewHelpers\BaseViewHelper;
-use TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase;
-
-class BaseViewHelperTest extends ViewHelperBaseTestcase
-{
-    /**
-     * @test
-     */
-    public function renderTakesBaseUriFromServerRequest()
-    {
-        $baseUri = 'http://typo3.org/';
-
-        /** @var NormalizedParams|ObjectProphecy $normalizedParams */
-        $normalizedParams = $this->prophesize(NormalizedParams::class);
-        $normalizedParams->getSiteUrl()->willReturn($baseUri);
-        /** @var ServerRequestInterface|ObjectProphecy $request */
-        $request = $this->prophesize(ServerRequestInterface::class);
-        $request->getAttribute('applicationType')->willReturn(SystemEnvironmentBuilder::REQUESTTYPE_FE);
-        $request->getAttribute('normalizedParams')->willReturn($normalizedParams->reveal());
-        $GLOBALS['TYPO3_REQUEST'] = $request->reveal();
-
-        $viewHelper = new BaseViewHelper();
-        $this->injectDependenciesIntoViewHelper($viewHelper);
-
-        self::assertSame('<base href="' . $baseUri . '" />', $viewHelper->render());
-    }
-}
diff --git a/typo3/sysext/fluid/Tests/UnitDeprecated/ViewHelpers/BaseViewHelperTest.php b/typo3/sysext/fluid/Tests/UnitDeprecated/ViewHelpers/BaseViewHelperTest.php
new file mode 100644 (file)
index 0000000..27ea30a
--- /dev/null
@@ -0,0 +1,48 @@
+<?php
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+namespace TYPO3\CMS\Fluid\Tests\UnitDeprecated\ViewHelpers;
+
+use Prophecy\Prophecy\ObjectProphecy;
+use Psr\Http\Message\ServerRequestInterface;
+use TYPO3\CMS\Core\Core\SystemEnvironmentBuilder;
+use TYPO3\CMS\Core\Http\NormalizedParams;
+use TYPO3\CMS\Fluid\ViewHelpers\BaseViewHelper;
+use TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase;
+
+class BaseViewHelperTest extends ViewHelperBaseTestcase
+{
+    /**
+     * @test
+     */
+    public function renderTakesBaseUriFromServerRequest()
+    {
+        $baseUri = 'http://typo3.org/';
+
+        /** @var NormalizedParams|ObjectProphecy $normalizedParams */
+        $normalizedParams = $this->prophesize(NormalizedParams::class);
+        $normalizedParams->getSiteUrl()->willReturn($baseUri);
+        /** @var ServerRequestInterface|ObjectProphecy $request */
+        $request = $this->prophesize(ServerRequestInterface::class);
+        $request->getAttribute('applicationType')->willReturn(SystemEnvironmentBuilder::REQUESTTYPE_FE);
+        $request->getAttribute('normalizedParams')->willReturn($normalizedParams->reveal());
+        $GLOBALS['TYPO3_REQUEST'] = $request->reveal();
+
+        $viewHelper = new BaseViewHelper();
+        $this->injectDependenciesIntoViewHelper($viewHelper);
+
+        self::assertSame('<base href="' . $baseUri . '" />', $viewHelper->render());
+    }
+}