How to add assets to data object via api


I exported all my data object and assets via a php script but I am not able to add pictures to each data objects galleries.

Is there something like that “$object->addPictureToObjectGallery(…);” available ?


first you need to create Hotspotimage object and add it to the list

   $items = [];
   $hotspot = new DataObject\Data\Hotspotimage();
   $items[] = $hotspot;

then you setItems to the ImageGallery

 $gallery = $object->getYourGallery();
1 Like

Thank you Krzysztof

It works fine but I have a problem if I want to add a single photo to an existing gallery : it erases the gallery to replace it with the last loaded photo.

I’m not sure how to fix this …


try sth like this:

$gallery = $object->getYourGallery();
$currentItems = $gallery->getItems();
array_push($currentItems, $hotspot);

Thanks again Krzysztof