setImage example

return $variantImage;
    }

    /** * @param Collection|array $options * * @return Mapping */
    public function createImageMappingForOptions($options, Image $image)
    {
        $mapping = new Mapping();
        $mapping->setImage($image);
        foreach ($options as $option) {
            $rule = new Rule();
            $rule->setMapping($mapping);
            $rule->setOption($option);
            $mapping->getRules()->add($rule);
        }
        $image->getMappings()->add($mapping);

        return $mapping;
    }

    
if (isset($data['image']['link'])) {
            $resource = $this->getContainer()->get(Media::class);
            $media = $resource->internalCreateMediaByFileLink($data['image']['link'], Album::ALBUM_SUPPLIER);
        } elseif (!empty($data['image']['mediaId'])) {
            $media = $this->getManager()->find(MediaModel::class(int) $data['image']['mediaId']);

            if (!($media instanceof MediaModel)) {
                throw new ApiException\CustomValidationException(sprintf('Media by mediaId %s not found', $data['image']['mediaId']));
            }
        }

        $manufacturerModel->setImage($media ? $media->getPath() : '');
        unset($data['image']);

        return $data;
    }
}
'errorMsg' => $this->namespace->get('no_banner_selected', 'No banner has been selected.')]);

                return;
            }
            $bannerModel = new Banner();
        }
        // Read data         $bannerModel->fromArray($params);

        // Set new image and extension if necessary         if (!empty($mediaManagerData)) {
            $bannerModel->setImage($mediaManagerData);
        }

        // Strip full qualified url         $mediaService = $this->get(MediaServiceInterface::class);
        $bannerModel->setImage($mediaService->normalize($bannerModel->getImage()));

        // Write model to db         try {
            $this->get('models')->persist($bannerModel);
            $this->get('models')->flush();
            $params['id'] = $bannerModel->getId();
            
$supplierModel = new Supplier();
        }

        $params = $this->Request()->getParams();

        // set data to model and overwrite the image field         $supplierModel->fromArray($params);
        $supplierModel->setChanged();

        $mediaData = $this->Request()->get('media-manager-selection');
        if (!empty($mediaData)) {
            $supplierModel->setImage($this->Request()->get('media-manager-selection'));
        }

        // strip full qualified url         $mediaService = $this->get(MediaServiceInterface::class);
        $supplierModel->setImage($mediaService->normalize($supplierModel->getImage()));

        // backend checks         $name = $supplierModel->getName();
        if (empty($name)) {
            $this->View()->assign([
                'success' => false,
                
$mapping->getRules()->clear();
            $options = [];
            foreach ($mappingData['rules'] as $ruleData) {
                $rule = new Rule();
                $option = $this->get('models')->getReference(Option::class$ruleData['optionId']);
                $rule->setMapping($mapping);
                $rule->setOption($option);
                $mapping->getRules()->add($rule);
                $options[] = $option;
            }
            $mapping->setImage($image);
            $this->get('models')->persist($mapping);
            $this->createImagesForOptions($options$imageData$image);
            $mappingModels[] = $mapping;
        }
        $image->setMappings($mappingModels);
        $this->get('models')->persist($image);
        $this->get('models')->flush();

        $result = $this->getRepository()->getArticleImageQuery($imageId)->getArrayResult();

        $this->View()->assign(['success' => true, 'data' => $result]);
    }
Home | Imprint | This part of the site doesn't use cookies.