[Flow] \DateTimeConverter

mario chiari ml at mariochiari.net
Mon Jun 3 22:19:36 CEST 2013


Hi Bastian, All,

On Mon, 2013-06-03 at 14:40 +0200, Bastian Waidelich wrote:
> mario chiari wrote:
> 
> Hi Mario,
> 
> > I have a Father/Son situations
> > [...] to define multiple Father, each with multiple Sons.

> 
> PropertyMapper::convert() expects a third parameter $configuration.
> You should be able to use that "manually":
> 
> 
> $propertyMappingConfiguration = new 
> \TYPO3\Flow\Property\PropertyMappingConfiguration();
> $propertyMappingConfiguration->forProperty('my_date')
> 	->setTypeConverterOption('TYPO3\Flow\Property\TypeConverter
>                 \DateTimeConverter', \TYPO3\Flow\Property\TypeConverter
>                 \DateTimeConverter::CONFIGURATION_DATE_FORMAT,'Y-m-d');}
> 
> $fatherObj = $propertyMapper->convert($father,'\...\Model
> \Father', $propertyMappingConfiguration);

YES, indeed the following works:

$propertyMappingConfiguration = new \TYPO3\Flow\Property
\PropertyMappingConfiguration();
$propertyMappingConfiguration->setTypeConverterOption('TYPO3\Flow
\Property\TypeConverter\PersistentObjectConverter',\TYPO3\Flow\Property
\TypeConverter
\PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED,TRUE); (*)
$propertyMappingConfiguration->allowAllProperties(); (*)
$propertyMappingConfiguration->forProperty('mydate')->setTypeConverterOption('TYPO3\Flow\Property\TypeConverter\DateTimeConverter', \TYPO3\Flow\Property\TypeConverter\DateTimeConverter::CONFIGURATION_DATE_FORMAT,'d-m-Y');

Note, Flow suggested the missing lines (*), very nice!

Now, say I have a further \datetime property birthdate for the son
objects. I am able to fix the createAction above to have a
DateTimeConverter for that nested property too. 

However, I am still missing something. How do I modify the following
updateAction+initializeUpdate (which works fine for the first level) for
the nested level:

public function initializeUpdateAction() {
	  $this->arguments['father']
	    ->getPropertyMappingConfiguration()
	    ->forProperty('mydate')
	    ->setTypeConverterOption('TYPO3\Flow\Property\TypeConverter
\DateTimeConverter',\TYPO3\Flow\Property\TypeConverter
\DateTimeConverter::CONFIGURATION_DATE_FORMAT,'d-m-Y');
	  }

	public function updateAction(\...\Model\Evento $father) {
		$this->fatherRepository->update($father);
                $this->redirect(...);
	}
?

Thanks for your help
cheers
mario






More information about the Flow mailing list