[BUGFIX] Add required option for imageManipulation type 07/49807/6
authorSascha Egerer <sascha@sascha-egerer.de>
Fri, 2 Sep 2016 22:09:12 +0000 (00:09 +0200)
committerFrans Saris <franssaris@gmail.com>
Sat, 3 Sep 2016 13:19:11 +0000 (15:19 +0200)
The TCA type imageManipulation should have support for a
"eval": ["required"] definition so you can enforce that the
cropping tool is opened.
This does make sense if you have aspect ratios defined and want
to enforce one of them.

Resolves: #77813
Releases: master
Change-Id: I517ec3cfe57e3a251219f47fa39c02447116ac08
Reviewed-on: https://review.typo3.org/49807
Tested-by: Bamboo TYPO3com <info@typo3.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Richard Haeser <richardhaeser@gmail.com>
Tested-by: Richard Haeser <richardhaeser@gmail.com>
Reviewed-by: Michiel Roos <michiel@maxserv.com>
Tested-by: Michiel Roos <michiel@maxserv.com>
Reviewed-by: Frans Saris <franssaris@gmail.com>
Tested-by: Frans Saris <franssaris@gmail.com>
typo3/sysext/backend/Classes/Form/Element/ImageManipulationElement.php
typo3/sysext/backend/Resources/Public/JavaScript/ImageManipulation.js

index 3626765..9542cb8 100644 (file)
@@ -118,17 +118,23 @@ class ImageManipulationElement extends AbstractFormElement
             ];
 
             $button = '<button class="btn btn-default t3js-image-manipulation-trigger"';
-            foreach ($buttonAttributes as $key => $value) {
-                $button .= ' ' . $key . '="' . htmlspecialchars($value) . '"';
-            }
+            $button .= GeneralUtility::implodeAttributes($buttonAttributes, true, true);
             $button .= '><span class="t3-icon fa fa-crop"></span>';
             $button .= htmlspecialchars($languageService->sL('LLL:EXT:lang/locallang_wizards.xlf:imwizard.open-editor'));
             $button .= '</button>';
 
-            $inputField = '<input type="hidden" '
-                . 'id="' . $formFieldId . '" '
-                . 'name="' . $parameterArray['itemFormElName'] . '" '
-                . 'value="' . htmlspecialchars($parameterArray['itemFormElValue']) . '" />';
+            $attributes = [];
+            $attributes['type'] = 'hidden';
+            $attributes['id'] = $formFieldId;
+            $attributes['name'] = $parameterArray['itemFormElName'];
+            $attributes['value'] = $parameterArray['itemFormElValue'];
+
+            $evalList = GeneralUtility::trimExplode(',', $config['eval'], true);
+            if (in_array('required', $evalList, true)) {
+                $attributes['data-formengine-validation-rules'] = $this->getValidationDataAsJsonString(['required' => true]);
+            }
+
+            $inputField = '<input ' . GeneralUtility::implodeAttributes($attributes, true, true) . '" />';
 
             $content .= $inputField . $button;
 
index 031fd67..d8fcb54 100644 (file)
@@ -255,6 +255,7 @@ define(['jquery', 'TYPO3/CMS/Backend/Modal', 'TYPO3/CMS/Backend/Severity'], func
                        $formGroup.find('.t3js-image-manipulation-preview').addClass('hide');
                }
                $formField.val(newValue);
+               $formField.trigger('change');
                ImageManipulation.dismiss();
        };