Form/DataTransformer/ProductPhotoCollectionToArrayTransformer.php
protected function createPhotosCollection(Product $product, $values)
    {
        $photos      = new ArrayCollection();
        $identifiers = $this->getMediaIdentifiers($values);
        $hierarchy   = 0;
        
        foreach ($identifiers as $id) {
            $media = $this->getMediaById($id);
            $photo = $this->getProductPhoto($media, $product, $values);
            $photo->setHierarchy($hierarchy++);
            if (!$photos->contains($photo)) {
                $photos->add($photo);
            }
        }
        
        return $photos;
    }
protected function createPhotosCollection(Product $product, $values)
    {
        $photos      = new ArrayCollection();
        $identifiers = $this->getMediaIdentifiers($values);
        $hierarchy   = 0;
        
        foreach ($identifiers as $id) {
            $media = $this->getMediaById($id);
            $photo = $this->getProductPhoto($media, $product, $values);
            $photo->setHierarchy($hierarchy++);
            if (!$photos->contains($photo)) {
                $photos->add($photo);
            }
        }
        
        return $photos;
    }
Returns new photos collection

@param Product $product
@param array   $values

@return ArrayCollection