diff --git a/composer.json b/composer.json index 9cc671cb75ea24a0e09350b82e38e4e903e160a5..4661a03b0a1292cec28b7ba2da56519c657b8a2e 100644 --- a/composer.json +++ b/composer.json @@ -315,7 +315,8 @@ "TYPO3Tests\\TestMeta\\": "typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_meta/Classes/", "TYPO3Tests\\TestTyposcriptAstFunctionEvent\\": "typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_typoscript_ast_function_event/Classes/", "TYPO3Tests\\TestTyposcriptPagetsconfigfactory\\": "typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_typoscript_pagetsconfigfactory/Classes/", - "TYPO3Tests\\TypeConverterTest\\": "typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/type_converter_test/Classes/" + "TYPO3Tests\\TypeConverterTest\\": "typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/type_converter_test/Classes/", + "TYPO3Tests\\ViewhelperLibrary\\": "typo3/sysext/fluid/Tests/Functional/Fixtures/Libraries/viewhelper_library/src/" } } } diff --git a/typo3/sysext/fluid/Classes/Core/ViewHelper/ViewHelperResolver.php b/typo3/sysext/fluid/Classes/Core/ViewHelper/ViewHelperResolver.php index f8b8a31095635db9871130cb0f0037886c427281..02e89d08c3730b7081a8e54d365ad35e56d0fed5 100644 --- a/typo3/sysext/fluid/Classes/Core/ViewHelper/ViewHelperResolver.php +++ b/typo3/sysext/fluid/Classes/Core/ViewHelper/ViewHelperResolver.php @@ -95,8 +95,13 @@ class ViewHelperResolver extends \TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperRes return $viewHelperInstance; } - /** @var ViewHelperInterface $viewHelperInstance */ - $viewHelperInstance = $this->container->get($viewHelperClassName); + if ($this->container->has($viewHelperClassName)) { + /** @var ViewHelperInterface $viewHelperInstance */ + $viewHelperInstance = $this->container->get($viewHelperClassName); + } else { + /** @var ViewHelperInterface $viewHelperInstance */ + $viewHelperInstance = new $viewHelperClassName(); + } return $viewHelperInstance; } diff --git a/typo3/sysext/fluid/Configuration/Services.yaml b/typo3/sysext/fluid/Configuration/Services.yaml index 4d6a5f44b9c4c3462a2ab6a5545bea5c30c13b69..aed2f9271518e7856075b7e02842f862ef673cbe 100644 --- a/typo3/sysext/fluid/Configuration/Services.yaml +++ b/typo3/sysext/fluid/Configuration/Services.yaml @@ -39,86 +39,3 @@ services: TYPO3Fluid\Fluid\Core\Parser\TemplateProcessor\NamespaceDetectionTemplateProcessor: public: true shared: false - - # VH's of base package - TYPO3Fluid\Fluid\ViewHelpers\Cache\DisableViewHelper: - tags: [ 'fluid.viewhelper' ] - autowire: false - TYPO3Fluid\Fluid\ViewHelpers\Cache\StaticViewHelper: - tags: [ 'fluid.viewhelper' ] - autowire: false - TYPO3Fluid\Fluid\ViewHelpers\Cache\WarmupViewHelper: - tags: [ 'fluid.viewhelper' ] - autowire: false - TYPO3Fluid\Fluid\ViewHelpers\Format\CdataViewHelper: - tags: [ 'fluid.viewhelper' ] - autowire: false - TYPO3Fluid\Fluid\ViewHelpers\Format\HtmlspecialcharsViewHelper: - tags: [ 'fluid.viewhelper' ] - autowire: false - TYPO3Fluid\Fluid\ViewHelpers\Format\PrintfViewHelper: - tags: [ 'fluid.viewhelper' ] - autowire: false - TYPO3Fluid\Fluid\ViewHelpers\Format\RawViewHelper: - tags: [ 'fluid.viewhelper' ] - autowire: false - TYPO3Fluid\Fluid\ViewHelpers\AliasViewHelper: - tags: [ 'fluid.viewhelper' ] - autowire: false - TYPO3Fluid\Fluid\ViewHelpers\CaseViewHelper: - tags: [ 'fluid.viewhelper' ] - autowire: false - TYPO3Fluid\Fluid\ViewHelpers\CommentViewHelper: - tags: [ 'fluid.viewhelper' ] - autowire: false - TYPO3Fluid\Fluid\ViewHelpers\CountViewHelper: - tags: [ 'fluid.viewhelper' ] - autowire: false - TYPO3Fluid\Fluid\ViewHelpers\CycleViewHelper: - tags: [ 'fluid.viewhelper' ] - autowire: false - TYPO3Fluid\Fluid\ViewHelpers\DebugViewHelper: - tags: [ 'fluid.viewhelper' ] - autowire: false - TYPO3Fluid\Fluid\ViewHelpers\DefaultCaseViewHelper: - tags: [ 'fluid.viewhelper' ] - autowire: false - TYPO3Fluid\Fluid\ViewHelpers\ElseViewHelper: - tags: [ 'fluid.viewhelper' ] - autowire: false - TYPO3Fluid\Fluid\ViewHelpers\ForViewHelper: - tags: [ 'fluid.viewhelper' ] - autowire: false - TYPO3Fluid\Fluid\ViewHelpers\GroupedForViewHelper: - tags: [ 'fluid.viewhelper' ] - autowire: false - TYPO3Fluid\Fluid\ViewHelpers\IfViewHelper: - tags: [ 'fluid.viewhelper' ] - autowire: false - TYPO3Fluid\Fluid\ViewHelpers\InlineViewHelper: - tags: [ 'fluid.viewhelper' ] - autowire: false - TYPO3Fluid\Fluid\ViewHelpers\LayoutViewHelper: - tags: [ 'fluid.viewhelper' ] - autowire: false - TYPO3Fluid\Fluid\ViewHelpers\OrViewHelper: - tags: [ 'fluid.viewhelper' ] - autowire: false - TYPO3Fluid\Fluid\ViewHelpers\RenderViewHelper: - tags: [ 'fluid.viewhelper' ] - autowire: false - TYPO3Fluid\Fluid\ViewHelpers\SectionViewHelper: - tags: [ 'fluid.viewhelper' ] - autowire: false - TYPO3Fluid\Fluid\ViewHelpers\SpacelessViewHelper: - tags: [ 'fluid.viewhelper' ] - autowire: false - TYPO3Fluid\Fluid\ViewHelpers\SwitchViewHelper: - tags: [ 'fluid.viewhelper' ] - autowire: false - TYPO3Fluid\Fluid\ViewHelpers\ThenViewHelper: - tags: [ 'fluid.viewhelper' ] - autowire: false - TYPO3Fluid\Fluid\ViewHelpers\VariableViewHelper: - tags: [ 'fluid.viewhelper' ] - autowire: false diff --git a/typo3/sysext/fluid/Tests/Functional/Fixtures/Libraries/viewhelper_library/composer.json b/typo3/sysext/fluid/Tests/Functional/Fixtures/Libraries/viewhelper_library/composer.json new file mode 100644 index 0000000000000000000000000000000000000000..af75e71bf365c66ec936bfa41353bb62b28a1e0d --- /dev/null +++ b/typo3/sysext/fluid/Tests/Functional/Fixtures/Libraries/viewhelper_library/composer.json @@ -0,0 +1,11 @@ +{ + "name": "typo3tests/viewhelper-library", + "description": "Standalone library to test viewhelpers without dependency injection", + "license": "GPL-2.0-or-later", + "type": "library", + "autoload": { + "psr-4": { + "TYPO3Tests\\ViewhelperLibrary\\": "src/" + } + } +} diff --git a/typo3/sysext/fluid/Tests/Functional/Fixtures/Libraries/viewhelper_library/src/ViewHelpers/TestViewHelper.php b/typo3/sysext/fluid/Tests/Functional/Fixtures/Libraries/viewhelper_library/src/ViewHelpers/TestViewHelper.php new file mode 100644 index 0000000000000000000000000000000000000000..206b8637f9736c4264b81ad51dc0133ee8337cfb --- /dev/null +++ b/typo3/sysext/fluid/Tests/Functional/Fixtures/Libraries/viewhelper_library/src/ViewHelpers/TestViewHelper.php @@ -0,0 +1,35 @@ +<?php + +declare(strict_types=1); + +/* + * 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 TYPO3Tests\ViewhelperLibrary\ViewHelpers; + +use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; +use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; +use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic; + +final class TestViewHelper extends AbstractViewHelper +{ + use CompileWithRenderStatic; + + public static function renderStatic( + array $arguments, + \Closure $renderChildrenClosure, + RenderingContextInterface $renderingContext + ) { + return 'test viewhelper working'; + } +} diff --git a/typo3/sysext/fluid/Tests/Functional/ViewhelperLibraryTest.php b/typo3/sysext/fluid/Tests/Functional/ViewhelperLibraryTest.php new file mode 100644 index 0000000000000000000000000000000000000000..1409f3e2db7da84503aef997c12011f1c7459910 --- /dev/null +++ b/typo3/sysext/fluid/Tests/Functional/ViewhelperLibraryTest.php @@ -0,0 +1,42 @@ +<?php + +declare(strict_types=1); + +/* + * 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\Functional; + +use TYPO3\CMS\Fluid\View\TemplateView; +use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; + +final class ViewhelperLibraryTest extends FunctionalTestCase +{ + protected bool $initializeDatabase = false; + + /** + * This test case covers the usage of standalone PHP libraries that provide + * Fluid ViewHelper classes. These libraries usually don't use TYPO3's + * dependency injection container and thus need to be supported separately + * in TYPO3's ViewHelperResolver implementation. + * + * @test + */ + public function viewhelperLibraryCanBeLoadedTest(): void + { + $view = new TemplateView(); + $view->getRenderingContext()->getViewHelperResolver()->addNamespace('fl', 'TYPO3Tests\\ViewhelperLibrary\\ViewHelpers'); + $view->getRenderingContext()->getTemplatePaths()->setTemplateSource('<fl:test />'); + self::assertSame('test viewhelper working', $view->render()); + } +}