[TYPO3-mvc] Copy object and add to repository

Fabian Fisahn fisahn at its-immaterial.com
Thu Apr 7 12:04:06 CEST 2011


Hi Franz,

On 07.04.11 11:16, Franz Koch wrote:
> Hey,
> 
>> Is there a comparable method for
>> Tx_Extbase_Persistence_LazyObjectStorage and/or
>> Tx_Extbase_Persistence_ObjectStorage?
>>
>> I didn't find something in the source.
> 
> Tx_Extbase_Persistence_LazyObjectStorage extends
> Tx_Extbase_Persistence_ObjectStorage, so you won't run into troubles
> with this when assigning it to a property expecting
> Tx_Extbase_Persistence_ObjectStorage.
> 
> But I think you're asking because the relations are not stored for your
> new object then. What you could do is this:
> 
> if ($propertyValue intstanceof Tx_Extbase_Persistence_LazyObjectStorage) {
>     $propertyValue = new
> Tx_Extbase_Persistence_ObjectStorage()->addAll($propertyValue);
> }
> 

after a small modification, it worked:

if (is_object($propertyValue) && $propertyValue instanceof
Tx_Extbase_Persistence_LazyObjectStorage) {
 	$tmpStorage =  new Tx_Extbase_Persistence_ObjectStorage();
	$tmpStorage->addAll($propertyValue);			
	$propertyValue = $tmpStorage;
}

Thank you!

Is that method of copying the object also a good solution for localize a
repository entriy?
I only need to change _localizedUid and _languageUid.

Or is there a smarter way?

Fabian



More information about the TYPO3-project-typo3v4mvc mailing list