[BUGFIX] Use correct typoscript settings in ClickEnlargeViewHelper
[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\Utility\GeneralUtility;
18 use TYPO3\CMS\Extbase\Service\TypoScriptService;
19 use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
20 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
21 use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
22
23 /**
24 * A view helper for creating a link for an image popup.
25 *
26 * = Example =
27 *
28 * <code title="enlarge image on click">
29 * <ce:link.clickEnlarge image="{image}" configuration="{settings.images.popup}"><img src=""></ce:link.clickEnlarge>
30 * </code>
31 *
32 * <output>
33 * <a href="url" onclick="javascript" target="thePicture"><img src=""></a>
34 * </output>
35 */
36 class ClickEnlargeViewHelper extends AbstractViewHelper {
37
38 /**
39 * Initialize ViewHelper arguments
40 *
41 * @return void
42 */
43 public function initializeArguments() {
44 $this->registerArgument('image', '', 'The original image file', TRUE);
45 $this->registerArgument(
46 'configuration',
47 'mixed',
48 'String, \TYPO3\CMS\Core\Resource\File or \TYPO3\CMS\Core\Resource\FileReference with link configuration',
49 TRUE
50 );
51 }
52
53 /**
54 * Render the view helper
55 *
56 * @return string
57 */
58 public function render() {
59 return self::renderStatic(
60 $this->arguments,
61 $this->buildRenderChildrenClosure(),
62 $this->renderingContext
63 );
64 }
65
66 /**
67 * @param array $arguments
68 * @param \Closure $renderChildrenClosure
69 * @param RenderingContextInterface $renderingContext
70 * @return string
71 */
72 static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) {
73 $image = $arguments['image'];
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 static protected function getContentObjectRenderer() {
85 return $GLOBALS['TSFE']->cObj;
86 }
87
88 /**
89 * @return TypoScriptService
90 */
91 static protected function getTypoScriptService() {
92 static $typoScriptService;
93 if ($typoScriptService === NULL) {
94 $typoScriptService = GeneralUtility::makeInstance(TypoScriptService::class);
95 }
96 return $typoScriptService;
97 }
98 }