[!!!][FEATURE] Streamline Fluid Styled Content and CSS Styled Content
[Packages/TYPO3.CMS.git] / typo3 / sysext / css_styled_content / Classes / ViewHelpers / Link / ClickEnlargeViewHelper.php
1 <?php
2 namespace TYPO3\CMS\CssStyledContent\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\Utility\GeneralUtility;
20 use TYPO3\CMS\Extbase\Service\TypoScriptService;
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 * @return void
49 */
50 public function initializeArguments()
51 {
52 $this->registerArgument('image', FileReference::class, 'The original image file', true);
53 $this->registerArgument(
54 'configuration',
55 'mixed',
56 'String, \TYPO3\CMS\Core\Resource\File or \TYPO3\CMS\Core\Resource\FileReference with link configuration',
57 true
58 );
59 }
60
61 /**
62 * Render the view helper
63 *
64 * @return string
65 */
66 public function render()
67 {
68 return self::renderStatic(
69 $this->arguments,
70 $this->buildRenderChildrenClosure(),
71 $this->renderingContext
72 );
73 }
74
75 /**
76 * @param array $arguments
77 * @param \Closure $renderChildrenClosure
78 * @param RenderingContextInterface $renderingContext
79 * @return string
80 */
81 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
82 {
83 $image = $arguments['image'];
84 if ($image instanceof FileInterface) {
85 self::getContentObjectRenderer()->setCurrentFile($image);
86 }
87 $configuration = self::getTypoScriptService()->convertPlainArrayToTypoScriptArray($arguments['configuration']);
88 $content = $renderChildrenClosure();
89 $configuration['enable'] = true;
90
91 return self::getContentObjectRenderer()->imageLinkWrap($content, $image, $configuration);
92 }
93
94 /**
95 * @return ContentObjectRenderer
96 */
97 protected static function getContentObjectRenderer()
98 {
99 return $GLOBALS['TSFE']->cObj;
100 }
101
102 /**
103 * @return TypoScriptService
104 */
105 protected static function getTypoScriptService()
106 {
107 static $typoScriptService;
108 if ($typoScriptService === null) {
109 $typoScriptService = GeneralUtility::makeInstance(TypoScriptService::class);
110 }
111 return $typoScriptService;
112 }
113 }