getMediaByPath example

/** * @return array */
    private function prepareElementExport(array $element, ParameterBag $syncData)
    {
        $assets = $syncData->get('assets', []);
        $data = $element['data'];

        foreach ($data as &$elementData) {
            if ($elementData['key'] === self::ELEMENT_DATA_KEY) {
                $assetPath = $elementData['value'];
                $media = $this->getMediaByPath($assetPath);

                if ($media) {
                    $assetHash = md5($media->getId());
                    $assets[$assetHash] = $this->mediaService->getUrl($assetPath);
                    $elementData['value'] = $assetHash;

                    break;
                }
            }
        }
        unset($elementData);

        
$this->generateLink($element$context);
        $this->addMappings($collection$element$context);
    }

    /** * {@inheritdoc} */
    public function handle(ResolvedDataCollection $collection, Element $element, ShopContextInterface $context)
    {
        $bannerPath = $element->getConfig()->get('file');
        $media = $collection->getMediaByPath($bannerPath);
        $element->getData()->set('media', $media);

        if ($media) {
            $fileInfo = ['width' => $media->getWidth(), 'height' => $media->getHeight()];
            $element->getConfig()->set('fileInfo', $fileInfo);
        }

        // hydrate mappings with products         $this->resolveMappings($collection$element);
    }

    
$medias = $this->storefrontMediaService->getList($mediaIds$context);

        foreach ($getBanners as &$getAffectedBanners) {
            // converting to old format             $getAffectedBanners['valid_from'] = $getAffectedBanners['validFrom'];
            $getAffectedBanners['valid_to'] = $getAffectedBanners['validTo'];
            $getAffectedBanners['link_target'] = $getAffectedBanners['linkTarget'];
            $getAffectedBanners['categoryID'] = $getAffectedBanners['categoryId'];

            $getAffectedBanners['img'] = $getAffectedBanners['image'];

            $media = $this->getMediaByPath($medias$getAffectedBanners['image']);
            if ($media !== null) {
                $media = $this->legacyStructConverter->convertMediaStruct($media);
                $getAffectedBanners['media'] = $media;
            }

            $bannerStatistics = $this->modelManager->getRepository(TrackingBanner::class)->getOrCreateBannerStatsModel($getAffectedBanners['id']);
            $bannerStatistics->increaseViews();
            $this->modelManager->persist($bannerStatistics);
            $this->modelManager->flush($bannerStatistics);

            if (!empty($getAffectedBanners['link'])) {
                
case 'webm_video':
                case 'ogg_video':
                case 'h264_video':
                case 'fallback_picture':
                    $assetPath = $this->mediaService->getUrl($elementData['value']);
            }

            if ($assetPath === null) {
                continue;
            }

            $media = $this->getMediaByPath($elementData['value']);

            if ($media) {
                $assetHash = md5($media->getId());
                $assets[$assetHash] = $assetPath;
                $elementData['value'] = $assetHash;
            }
        }
        unset($elementData);

        $syncData->set('assets', $assets);
        $element['data'] = $data;

        
break;
        }
    }

    public function handle(ResolvedDataCollection $collection, Element $element, ShopContextInterface $context)
    {
        $imageType = $element->getConfig()->get('image_type');
        $key = ComponentHandlerInterface::CRITERIA_KEY . $element->getId();

        switch ($imageType) {
            case self::TYPE_IMAGE:
                $media = $collection->getMediaByPath($element->getConfig()->get('image'));
                if (!$media) {
                    break;
                }

                $element->getData()->set('media', $media);
                break;

            case self::TYPE_ARTICLE_OR_BLOG:
                $isBlog = (bool) $element->getConfig()->get('blog_category');
                $categoryId = (int) $element->getConfig()->get('category_selection');

                
/** * @return array */
    private function prepareElementExport(array $element, ParameterBag $syncData)
    {
        $assets = $syncData->get('assets', []);
        $data = $element['data'];

        foreach ($data as &$elementData) {
            if ($elementData['key'] === self::ELEMENT_DATA_KEY && !empty($elementData['value'])) {
                $assetPath = $elementData['value'];
                $media = $this->getMediaByPath($assetPath);

                if ($media) {
                    $assetHash = md5($media->getId());

                    $assets[$assetHash] = $this->mediaService->getUrl($assetPath);
                    $elementData['value'] = $assetHash;

                    break;
                }
            }
        }
        
$data = $element['data'];

        /** @var array $elementData */
        foreach ($data as &$elementData) {
            if ($elementData['key'] === self::ELEMENT_DATA_KEY) {
                $sliders = json_decode($elementData['value'], true);
                if (!\is_array($sliders)) {
                    break;
                }

                foreach ($sliders as $key => &$slide) {
                    $media = $this->getMediaByPath($slide['path']);

                    if ($media) {
                        $assetHash = md5($media->getId());
                        $assets[$assetHash] = $this->mediaService->getUrl($slide['path']);
                        $slide['path'] = $assetHash;
                    }
                }
                unset($slide);
                $elementData['value'] = json_encode($sliders);

                break;
            }
Home | Imprint | This part of the site doesn't use cookies.