2e4d06255cc1b28f30613c8067218028067fabca
[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
25 /**
26 * A view helper for creating a link for an image popup.
27 *
28 * = Example =
29 *
30 * <code title="enlarge image on click">
31 * <ce:link.clickEnlarge image="{image}" configuration="{settings.images.popup}"><img src=""></ce:link.clickEnlarge>
32 * </code>
33 *
34 * <output>
35 * <a href="url" onclick="javascript" target="thePicture"><img src=""></a>
36 * </output>
37 */
38 class ClickEnlargeViewHelper extends AbstractViewHelper
39 {
40 /**
41 * @var bool
42 */
43 protected $escapeOutput = false;
44
45 /**
46 * Initialize ViewHelper arguments
47 */
48 public function initializeArguments()
49 {
50 $this->registerArgument('image', FileReference::class, 'The original image file', true);
51 $this->registerArgument(
52 'configuration',
53 'mixed',
54 'String, \TYPO3\CMS\Core\Resource\File or \TYPO3\CMS\Core\Resource\FileReference with link configuration',
55 true
56 );
57 }
58
59 /**
60 * Render the view helper
61 *
62 * @return string
63 */
64 public function render()
65 {
66 return self::renderStatic(
67 $this->arguments,
68 $this->buildRenderChildrenClosure(),
69 $this->renderingContext
70 );
71 }
72
73 /**
74 * @param array $arguments
75 * @param \Closure $renderChildrenClosure
76 * @param RenderingContextInterface $renderingContext
77 * @return string
78 */
79 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
80 {
81 $image = $arguments['image'];
82 if ($image instanceof FileInterface) {
83 self::getContentObjectRenderer()->setCurrentFile($image);
84 }
85 $configuration = self::getTypoScriptService()->convertPlainArrayToTypoScriptArray($arguments['configuration']);
86 $content = $renderChildrenClosure();
87 $configuration['enable'] = true;
88
89 return self::getContentObjectRenderer()->imageLinkWrap($content, $image, $configuration);
90 }
91
92 /**
93 * @return ContentObjectRenderer
94 */
95 protected static function getContentObjectRenderer()
96 {
97 return $GLOBALS['TSFE']->cObj;
98 }
99
100 /**
101 * @return TypoScriptService
102 */
103 protected static function getTypoScriptService()
104 {
105 static $typoScriptService;
106 if ($typoScriptService === null) {
107 $typoScriptService = GeneralUtility::makeInstance(TypoScriptService::class);
108 }
109 return $typoScriptService;
110 }
111 }