1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Get the URI of the cropped image. |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace HDNET\Focuspoint\ViewHelpers\Uri; |
8
|
|
|
|
9
|
|
|
use HDNET\Focuspoint\Service\FocusCropService; |
10
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
11
|
|
|
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Get the URI of the cropped image. |
15
|
|
|
*/ |
16
|
|
|
class ImageViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Uri\ImageViewHelper |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Initialize ViewHelper arguments. |
20
|
|
|
*/ |
21
|
|
|
public function initializeArguments() |
22
|
|
|
{ |
23
|
|
|
parent::initializeArguments(); |
24
|
|
|
$this->registerArgument('ratio', 'string', 'Ratio of the image', false, '1:1'); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param array $arguments |
29
|
|
|
* @param callable|\Closure $renderChildrenClosure |
30
|
|
|
* @param RenderingContextInterface $renderingContext |
31
|
|
|
* |
32
|
|
|
* @throws \TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException |
33
|
|
|
* @throws \TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException |
34
|
|
|
* |
35
|
|
|
* @return string |
36
|
|
|
*/ |
37
|
|
|
public static function renderStatic( |
38
|
|
|
array $arguments, |
39
|
|
|
\Closure $renderChildrenClosure, |
40
|
|
|
RenderingContextInterface $renderingContext |
41
|
|
|
) { |
42
|
|
|
/** @var FocusCropService $service */ |
43
|
|
|
$service = GeneralUtility::makeInstance(FocusCropService::class); |
44
|
|
|
$arguments['src'] = $service->getCroppedImageSrcForViewHelper( |
45
|
|
|
$arguments['src'], |
46
|
|
|
$arguments['image'], |
47
|
|
|
$arguments['treatIdAsReference'], |
48
|
|
|
$arguments['ratio'] |
49
|
|
|
); |
50
|
|
|
$arguments['image'] = null; |
51
|
|
|
$arguments['treatIdAsReference'] = false; |
52
|
|
|
|
53
|
|
|
return \TYPO3\CMS\Fluid\ViewHelpers\Uri\ImageViewHelper::renderStatic($arguments, $renderChildrenClosure, $renderingContext); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|