[TYPO3-english] TypeConverter and CONFIGURATION_OVERRIDE_TARGET_TYPE_ALLOWED

Viktor Livakivskyi invisible.kinder at gmail.com
Tue Sep 8 19:32:17 CEST 2015


Hi, List.

I'm bothering here again with some non-trivial questions =)

This time I want to create an Object, which is a child of base object. 

I have a form, which crates MyObject, controller action, which expects MyObject as argument. There are two children of MyObject: MyFirstChild and MySecondChild. Type of object, that is created, can be defined only after user input. Let's say, there is a field 'code' in Fluid form, which corresponds to $code in MyObject. If 'code' starts with 01 - it is MyFirstChild, if 02 - MySecondChild.

I decided to use custom TypeConverter for this. Inherited from PersistentObjectConverter, overloaded getTargetTypeForSource() and, actually I could directly return desired type from within this method, but I've noticed, that PersistentObjectConverter itself checks fro sub-types. It expects CONFIGURATION_OVERRIDE_TARGET_TYPE_ALLOWED set to TRUE and $source['__type'].

Currently I'm doing it so:

public function getTargetTypeForSource($source, $originalTargetType, \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = NULL) {
		$source['__type'] = $this->determineType($source);

		$configuration->setTypeConverterOption(
			__CLASS__,
			self::CONFIGURATION_OVERRIDE_TARGET_TYPE_ALLOWED,
			TRUE
		);

		return parent::getTargetTypeForSource($source, $originalTargetType, $configuration);
	}


But it looks hacky for me, especially due to a fact, that PropertyMappingConfigurationInterface doesn't contain setTypeConverterOption() method.

And I don't want to move setTypeConverterOption() call to controller, bcs controller should be dumb and don't know, that there is some magic in object instantiation.

So, here comes a question: how type overriding during object instantiation is supposed to be used? For me it seems, that Extbase itself can somehow detect a sub-type (as it perfectly does, when persisting object or fetching from repository), but I'm too blind to find the correct path...


More information about the TYPO3-english mailing list