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