2 namespace TYPO3\CMS\Backend\Form\Element;
18 use TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException;
37 'file_field' =>
'uid_local',
38 'enableZoom' =>
false,
39 'allowedExtensions' => null,
41 '1.7777777777777777' =>
'LLL:EXT:lang/locallang_wizards.xlf:imwizard.ratio.16_9',
42 '1.3333333333333333' =>
'LLL:EXT:lang/locallang_wizards.xlf:imwizard.ratio.4_3',
43 '1' =>
'LLL:EXT:lang/locallang_wizards.xlf:imwizard.ratio.1_1',
44 'NaN' =>
'LLL:EXT:lang/locallang_wizards.xlf:imwizard.ratio.free',
58 $row = $this->data[
'databaseRow'];
59 $parameterArray = $this->data[
'parameterArray'];
62 if (isset($parameterArray[
'fieldConf'][
'config'][
'ratios'])) {
63 unset($this->defaultConfig[
'ratios']);
65 $config = ArrayUtility::arrayMergeRecursiveOverrule($this->defaultConfig, $parameterArray[
'fieldConf'][
'config']);
68 if ($config[
'allowedExtensions'] === null) {
69 $config[
'allowedExtensions'] =
$GLOBALS[
'TYPO3_CONF_VARS'][
'GFX'][
'imagefile_ext'];
72 if ($config[
'readOnly']) {
74 $options[
'parameterArray'] = array(
78 'itemFormElValue' => $parameterArray[
'itemFormElValue'],
80 $options[
'renderType'] =
'none';
81 return $this->nodeFactory->create($options)->render();
84 $file = $this->
getFile($row, $config[
'file_field']);
91 if (
GeneralUtility::inList(mb_strtolower($config[
'allowedExtensions']), mb_strtolower($file->getExtension()))) {
94 $preview = $this->
getPreview($file, $parameterArray[
'itemFormElValue']);
97 foreach ((array)$config[
'ratios'] as $ratio => $label) {
98 $config[
'ratios'][$ratio] = $languageService->sL($label,
true);
103 'zoom' => $config[
'enableZoom'] ?
'1' :
'0',
104 'ratios' => json_encode($config[
'ratios']),
105 'file' => $file->getUid(),
107 $wizardData[
'token'] =
GeneralUtility::hmac(implode(
'|', $wizardData),
'ImageManipulationWizard');
109 $buttonAttributes = array(
110 'data-url' => BackendUtility::getAjaxUrl(
'wizard_image_manipulation', $wizardData),
111 'data-severity' =>
'notice',
112 'data-image-name' => $file->getNameWithoutExtension(),
113 'data-image-uid' => $file->getUid(),
114 'data-file-field' => $config[
'file_field'],
115 'data-field' => $formFieldId,
118 $button =
'<button class="btn btn-default t3js-image-manipulation-trigger"';
119 foreach ($buttonAttributes as $key => $value) {
120 $button .=
' ' . $key .
'="' . htmlspecialchars($value) .
'"';
122 $button .=
'><span class="t3-icon fa fa-crop"></span>';
123 $button .= $languageService->sL(
'LLL:EXT:lang/locallang_wizards.xlf:imwizard.open-editor',
true);
124 $button .=
'</button>';
126 $inputField =
'<input type="hidden" '
127 .
'id="' . $formFieldId .
'" '
128 .
'name="' . $parameterArray[
'itemFormElName'] .
'" '
129 .
'value="' . htmlspecialchars($parameterArray[
'itemFormElValue']) .
'" />';
131 $content .= $inputField . $button;
135 $resultArray[
'requireJsModules'][] = array(
136 'TYPO3/CMS/Backend/ImageManipulation' =>
'function(ImageManipulation){ImageManipulation.initializeTrigger()}'
140 $content .=
'<p class="text-muted"><em>' . $languageService->sL(
'LLL:EXT:lang/locallang_wizards.xlf:imwizard.supported-types-message',
true) .
'<br />';
142 $content .=
'</em></p>';
144 $item =
'<div class="media">';
146 $item .=
'<div class="media-body">' . $content .
'</div>';
149 $resultArray[
'html'] = $item;
160 protected function getFile(array $row, $fieldName)
163 $fileUid = !empty($row[$fieldName]) ? $row[$fieldName] : null;
164 if (strpos($fileUid,
'sys_file_') === 0) {
165 if (strpos($fileUid,
'|')) {
168 $fileUid = explode(
'|', $fileUid);
169 $fileUid = $fileUid[0];
171 $fileUid = substr($fileUid, 9);
177 }
catch (\InvalidArgumentException $e) {
196 $imageSetup = array(
'maxWidth' => $maxWidth,
'maxHeight' => $maxHeight,
'crop' => $crop);
199 if ($processedImage->getProperty(
'width')) {
200 $imageUrl = $processedImage->getPublicUrl(
true);
201 $thumbnail =
'<img src="' . $imageUrl .
'" ' .
202 'class="thumbnail thumbnail-status" ' .
203 'width="' . $processedImage->getProperty(
'width') .
'" ' .
204 'height="' . $processedImage->getProperty(
'height') .
'" >';
208 $preview =
'<div class="media-left">';
209 $preview .=
'<div class="t3js-image-manipulation-preview media-object' . ($thumbnail ?
'' :
' hide') .
'" ';
211 $preview .=
'data-preview-width="' . $maxWidth .
'" data-preview-height="' . $maxHeight .
'">';
212 $preview .= $thumbnail;
213 $preview .=
'</div></div>';
227 $imageManipulation = null;
228 $x = $y = $width = $height = 0;
231 if ($rawImageManipulationValue) {
232 $imageManipulation = json_decode($rawImageManipulationValue);
233 if (is_object($imageManipulation)) {
234 $x = (int)$imageManipulation->x;
235 $y = (
int)$imageManipulation->y;
236 $width = (int)$imageManipulation->width;
237 $height = (
int)$imageManipulation->height;
239 $imageManipulation = null;
244 $content .=
'<div class="table-fit-block table-spacer-wrap">';
245 $content .=
'<table class="table table-no-borders t3js-image-manipulation-info' . ($imageManipulation === null ?
' hide' :
'') .
'">';
246 $content .=
'<tr><td>' . $languageService->sL(
'LLL:EXT:lang/locallang_wizards.xlf:imwizard.crop-x',
true) .
'</td>';
247 $content .=
'<td class="t3js-image-manipulation-info-crop-x">' . $x .
'px</td></tr>';
248 $content .=
'<tr><td>' . $languageService->sL(
'LLL:EXT:lang/locallang_wizards.xlf:imwizard.crop-y',
true) .
'</td>';
249 $content .=
'<td class="t3js-image-manipulation-info-crop-y">' . $y .
'px</td></tr>';
250 $content .=
'<tr><td>' . $languageService->sL(
'LLL:EXT:lang/locallang_wizards.xlf:imwizard.crop-width',
true) .
'</td>';
251 $content .=
'<td class="t3js-image-manipulation-info-crop-width">' . $width .
'px</td></tr>';
252 $content .=
'<tr><td>' . $languageService->sL(
'LLL:EXT:lang/locallang_wizards.xlf:imwizard.crop-height',
true) .
'</td>';
253 $content .=
'<td class="t3js-image-manipulation-info-crop-height">' . $height .
'px</td></tr>';
254 $content .=
'</table>';
255 $content .=
'</div>';