[TYPO3-mvc] T3 6.2 Exception while property mapping / CONFIGURATION_CREATION_ALLOWED
g4-lisz at tonarchiv.ch
g4-lisz at tonarchiv.ch
Mon Aug 25 17:21:50 CEST 2014
On 08/22/2014 01:31 PM, g4-lisz at tonarchiv.ch wrote:
> Hi there
>
> I have some issue with a action controller when updating data from a
> form viewhelper.
>
> The extension worked in 4.6. Now I get this '#1297759968: Exception
> while property mapping at property path "type":Creation of objects not
> allowed. To enable this, you need to set the
> PropertyMappingConfiguration Value "CONFIGURATION_CREATION_ALLOWED" to
> TRUE' error.
>
> "Type" is derived from the AbstractValueObject class. It's a property of
> the new object "newPdfbericht" to be added, and it is selected by radio
> buttons:
>
> <f:form enctype="multipart/form-data"
> action="qualitaetsberichteUpdate" name="newPdfbericht"
> object="{newPdfbericht}">
> <f:form.upload name="file"/>
> ....
> <f:for each="{pdfberichtTypes}" as="pdfberichtType">
> <label>
> <f:form.radio property="type"
> value="{pdfberichtType}"/>
> {pdfberichtType.name}
> <br />
> </label>
> </f:for>
> </f:form>
>
> $pdfberichtTypes = $this->pdfberichtTypeRepository->findAll();
>
> The rendered HTML for the radio form field looks like this:
> <label>
> <input type="radio" value="1"
> name="tx_hplusinfo_pa_qualitaetsberichte[newPdfbericht][type][__identity]">
> Struktur H+
> <br>
> <label>
> <input type="radio" value="2"
> name="tx_hplusinfo_pa_qualitaetsberichte[newPdfbericht][type][__identity]">
> eigene Struktur
> <br>
> </label>
>
> I don't understand why the property mapper has to create a new "Type"
> object...
>
> Nevertheless, I added this intialieze function to the controller:
> /**
> * @return void
> */
> protected function initializeQualitaetsberichteUpdateAction() {
> $propertyMappingConfiguration =
> $this->arguments['newPdfbericht']->getPropertyMappingConfiguration();
> $propertyMappingConfiguration->allowAllProperties()
>
> ->setTypeConverterOption('TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter',
> \TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED,
> TRUE);
> }
>
> But still the same error. What I'm doing wrong? Maybe a TCA issue of
> PpdfberichetType" or "PdfBericht"?
>
> Any help would be much appreciated! I'm really stuck here...
After doing a lot of research over the weekend, i found reasons for the
issue and two solutions:
First I changed the type of the property object from AbstractValueObject
to AbstarctEntity. It solved the problem, but this coudn't be the right
solution to this issue...
So I went through the source code of PersistentObjectConverter class,
and I found this lines:
if (
class_exists($targetType)
&& is_subclass_of($targetType,
'TYPO3\\CMS\\Extbase\\DomainObject\\AbstractValueObject')
) {
// Unset identity for valueobject to use constructor mapping,
since the identity is determined from
// constructor arguments
unset($source['__identity']);
}
$object = $this->handleArrayData($source, $targetType,
$convertedChildProperties, $configuration);
That's why it want's to create a new object. But why does it not work in
my case? Later on in handleArrayData() are these lines:
if ($configuration === NULL ||
$configuration->getConfigurationValue('TYPO3\\CMS\\Extbase\\Property\\TypeConverter\\PersistentObjectConverter',
self::CONFIGURATION_CREATION_ALLOWED) !== TRUE)
{
throw new
\TYPO3\CMS\Extbase\Property\Exception\InvalidPropertyMappingConfigurationException('Creation
of objects not allowed. To enable this, you need to set the
PropertyMappingConfiguration Value "CONFIGURATION_CREATION_ALLOWED" to
TRUE');
}
$object = $this->buildObject($convertedChildProperties, $targetType);
There must be something wrong with my mapping configuration... And voilà:
$this->arguments['newPdfbericht']
->getPropertyMappingConfiguration()
->forProperty('type')
->setTypeConverterOption('TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter',
\TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED,
TRUE);
That was it!
And: There was another quick and dirty solution which i found on my way
reading the source code of PersistentObjectConverter.php:
In the form viewehelper, just add the UID of the AbstractValueObject as
a string, i.e.
<f:form.radio property="vtypeprop" value="{vtypeprop.uid}"/> in place of
<f:form.radio property="vtypeprop" value="{vtypeprop}"/>
If PersistentObjectConverter gets a string, it is assumed to be a UID,
and the object is loaded from storage.
Cheers,
Till
More information about the TYPO3-project-typo3v4mvc
mailing list