Skip to content

Commit

Permalink
[BUGFIX] Set PropertyMappingConfiguration for image uploads
Browse files Browse the repository at this point in the history
This change configures the ``PropertyMapper`` to allow mapping the
``resource`` to the ``image`` object.

Change-Id: I9672f0b90d2ec879af7e10806bc8413b8a704949
Releases: master, 2.0
  • Loading branch information
Rens Admiraal authored and Bastian Waidelich committed Jul 22, 2015
1 parent 23277a0 commit f2c6575
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Classes/TYPO3/Form/FormElements/ImageUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
* */

use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Property\PropertyMappingConfiguration;
use TYPO3\Flow\Property\TypeConverter\PersistentObjectConverter;
use TYPO3\Media\TypeConverter\AssetInterfaceConverter;

/**
* An image upload form element
Expand All @@ -22,6 +25,13 @@ class ImageUpload extends \TYPO3\Form\Core\Model\AbstractFormElement {
* @return void
*/
public function initializeFormElement() {
/** @var PropertyMappingConfiguration $propertyMappingConfiguration */
$propertyMappingConfiguration = $this->getRootForm()->getProcessingRule($this->getIdentifier())->getPropertyMappingConfiguration();

$propertyMappingConfiguration->setTypeConverterOption(PersistentObjectConverter::class, PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED, TRUE);
$propertyMappingConfiguration->setTypeConverterOption(AssetInterfaceConverter::class, AssetInterfaceConverter::CONFIGURATION_ONE_PER_RESOURCE, TRUE);
$propertyMappingConfiguration->allowProperties('resource');

$this->setDataType('TYPO3\Media\Domain\Model\Image');
$imageTypeValidator = new \TYPO3\Media\Validator\ImageTypeValidator(array('allowedTypes' => $this->properties['allowedTypes']));
$this->addValidator($imageTypeValidator);
Expand Down

0 comments on commit f2c6575

Please sign in to comment.