[Flow] Dynamically add element to array collection with fluid form

Christian Loock chl at vkf-renzel.de
Wed Aug 13 11:12:26 CEST 2014


Ok nevermind,

nothing is created. I only dont get any exceptions anymore. Which doesnt 
really help at all :D


On 13.08.2014 10:44, Christian Loock wrote:
> Hi,
>
> this is how I did it:
>
>     public function initializeUpdateAction()
>     {
>         $databaseServerMappingConfiguration = 
> $this->arguments->getArgument('databaseServer')->getPropertyMappingConfiguration();
>         /* @var $commentConfiguration 
> \TYPO3\Flow\Property\PropertyMappingConfiguration */
> $databaseServerMappingConfiguration->forProperty('databaseUsers')->allowAllProperties(); 
>
>         $databaseServer = $this->request->getArgument('databaseServer');
>         $databaseUsers = $databaseServer['databaseUsers'];
>         // \TYPO3\Flow\var_dump($databaseUsers);
>         foreach ($databaseUsers as $key => $databaseUser) {
> $databaseServerMappingConfiguration->forProperty('databaseUsers.' . 
> $key)->allowAllProperties();
>
> $databaseServerMappingConfiguration->allowCreationForSubProperty('databaseUsers.' 
> . $key);
> $databaseServerMappingConfiguration->allowModificationForSubProperty('databaseUsers.' 
> . $key);
>         }
>
>     }
>
>
> It works without exceptions, and the database users get created. 
> However, they dont have the reference to the databaseServer set :(
>
>
>
>
>
> On 13.08.2014 09:58, Carsten Bleicker wrote:
>> The dynamic fields are not known to trusted properties wich is usualy 
>> build up by any formfield viewhelper.
>> I think in case of dynamic fields you need an initializeFooAction() 
>> wich allows these dynamic subsets.
>>
>> something like this:
>>     /**
>>      * @return void
>>      */
>>     protected function initializeCreateAction() {
>>         $databaseServerMappingConfiguration = 
>> $this->arguments->getArgument('databaseServer')->getPropertyMappingConfiguration();
>>         /** @var array $databaseServers */
>>         $databaseServers = 
>> $this->request->getArgument('databaseServer');
>>         foreach ($databaseServers as $key => $server) {
>> $databaseServerMappingConfiguration->forProperty('databaseUsers.' . 
>> $key)->allowAllProperties();
>>         }
>>     }
>>
>>
>> ----------------------
>>
>> Carsten Bleicker
>> Wülfingstraße 1
>> 42477 Radevormwald
>>
>> E-Mail:    carsten at bleicker.de
>> Web:    www.bleicker.de
>> Twitter:    @carstenbleicker
>> Jabber:    cbleicker at jabber.ccc.de
>> Telefon:    +49 (0)171-2690845
>>
>> Am 13.08.2014 um 09:41 schrieb Christian Loock <chl at vkf-renzel.de>:
>>
>>> Hello,
>>>
>>> I am trying to build a form with fluid, that automatically adds 
>>> entries to an ArrayCollection. The collection consists of entities, 
>>> that shoukd be dynamically created and added to the collection. 
>>> Inside the form, i add new fields via javascript.
>>>
>>> The generated fluid form looks somewhat like this:
>>>
>>>
>>>
>>>             <input 
>>> placeholder="databaseServer.databaseuser.username" 
>>> class="form-control" type="text" 
>>> name="databaseServer[databaseUsers][0][username]" value="xxx">
>>>             <input 
>>> placeholder="databaseServer.databaseuser.password" 
>>> class="form-control" type="password" 
>>> name="databaseServer[databaseUsers][0][password]" value="xxx">
>>>             <input 
>>> placeholder="databaseServer.databaseuser.username" 
>>> class="form-control" type="text" 
>>> name="databaseServer[databaseUsers][1][username]" value="xxx">
>>>             <input 
>>> placeholder="databaseServer.databaseuser.password" 
>>> class="form-control" type="password" 
>>> name="databaseServer[databaseUsers][1][password]" value="xxx">
>>>
>>>
>>> The first entry, is an existing entity. When I only try to submit 
>>> the form with this one in it, it will safe with no problem.
>>> However, when i try to add a new row to the form, so that there is 
>>> an entry that does not exist in the database, I get an exception:
>>>
>>>
>>>    1297759968: Exception while property mapping for target type
>>>    "VKF\Deployment\Domain\Model\DatabaseServer", at property path
>>>    "databaseUsers": It is not allowed to map property "1".
>>>
>>> You need to use $propertyMappingConfiguration->allowProperties('1') 
>>> to enable mapping of this property.
>>>
>>>
>>> Does anybody know, why this happens?
>>>
>>>
>>>
>>> _______________________________________________
>>> Flow mailing list
>>> Flow at lists.typo3.org
>>> http://lists.typo3.org/cgi-bin/mailman/listinfo/flow
>>
>>
>> _______________________________________________
>> Flow mailing list
>> Flow at lists.typo3.org
>> http://lists.typo3.org/cgi-bin/mailman/listinfo/flow
>

-- 
Christian Loock
Web Developer
Renzel Agentur
www.renzel-agentur.de



More information about the Flow mailing list