[TASK] Convert remaining ViewHelpers to static calling
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid_styled_content / Classes / ViewHelpers / Link / ClickEnlargeViewHelper.php
1 <?php
2 namespace TYPO3\CMS\FluidStyledContent\ViewHelpers\Link;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Resource\FileInterface;
18 use TYPO3\CMS\Core\Resource\FileReference;
19 use TYPO3\CMS\Core\TypoScript\TypoScriptService;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
22 use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
23 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
24 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
25
26 /**
27 * A view helper for creating a link for an image popup.
28 *
29 * = Example =
30 *
31 * <code title="enlarge image on click">
32 * <ce:link.clickEnlarge image="{image}" configuration="{settings.images.popup}"><img src=""></ce:link.clickEnlarge>
33 * </code>
34 *
35 * <output>
36 * <a href="url" onclick="javascript" target="thePicture"><img src=""></a>
37 * </output>
38 */
39 class ClickEnlargeViewHelper extends AbstractViewHelper
40 {
41 use CompileWithRenderStatic;
42
43 /**
44 * @var bool
45 */
46 protected $escapeOutput = false;
47
48 /**
49 * Initialize ViewHelper arguments
50 */
51 public function initializeArguments()
52 {
53 $this->registerArgument('image', FileReference::class, 'The original image file', true);
54 $this->registerArgument(
55 'configuration',
56 'mixed',
57 'String, \TYPO3\CMS\Core\Resource\File or \TYPO3\CMS\Core\Resource\FileReference with link configuration',
58 true
59 );
60 }
61
62 /**
63 * @param array $arguments
64 * @param \Closure $renderChildrenClosure
65 * @param RenderingContextInterface $renderingContext
66 * @return string
67 */
68 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
69 {
70 $image = $arguments['image'];
71 if ($image instanceof FileInterface) {
72 self::getContentObjectRenderer()->setCurrentFile($image);
73 }
74 $configuration = self::getTypoScriptService()->convertPlainArrayToTypoScriptArray($arguments['configuration']);
75 $content = $renderChildrenClosure();
76 $configuration['enable'] = true;
77
78 return self::getContentObjectRenderer()->imageLinkWrap($content, $image, $configuration);
79 }
80
81 /**
82 * @return ContentObjectRenderer
83 */
84 protected static function getContentObjectRenderer()
85 {
86 return $GLOBALS['TSFE']->cObj;
87 }
88
89 /**
90 * @return TypoScriptService
91 */
92 protected static function getTypoScriptService()
93 {
94 static $typoScriptService;
95 if ($typoScriptService === null) {
96 $typoScriptService = GeneralUtility::makeInstance(TypoScriptService::class);
97 }
98 return $typoScriptService;
99 }
100 }