setPreview example

/** * @param array $data * * @return Media */
    public function createMedia($data)
    {
        $media = new Media();
        $media->setId($data['id']);
        $media->setExtension($data['extension']);
        $media->setName($data['name']);
        $media->setPreview($data['preview']);
        $media->setType($data['type']);
        $media->setFile($data['file']);
        $media->setDescription($data['description']);

        $me = $this;
        $thumbnails = array_map(function D$thumbnailData) use ($me) {
            return $me->createThumbnail($thumbnailData);
        }$data['thumbnails']);

        $media->setThumbnails($thumbnails);
        $media->addAttributes($this->createAttributes($data['attributes']));

        
/** * @return Media */
    public function hydrateProductImage(array $data)
    {
        $media = $this->hydrate($data);

        $translation = $this->getTranslation($data, '__image');
        $data = array_merge($data$translation);

        $media->setName($data['__image_description']);
        $media->setPreview($data['__image_main'] == 1);

        if (!empty($data['__imageAttribute_id'])) {
            $this->attributeHydrator->addAttribute($media$data, 'imageAttribute', 'image', 'image');
        }

        return $media;
    }

    private function isUpdateRequired(Media $media, array $data): bool
    {
        if ($media->getType() !== Media::TYPE_IMAGE) {
            
Home | Imprint | This part of the site doesn't use cookies.