Media example

return $option;
    }

    /** * @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);
        },
if (!$file->isValid()) {
                throw new Exception('The file exceeds the max file size.');
            }
        } catch (Exception $e) {
            $this->View()->assign(['success' => false, 'message' => $e->getMessage()]);

            return;
        }

        // Create a new model and set the properties         $media = new Media();

        $albumId = !empty($params['albumID']) ? $params['albumID'] : self::UNSORTED_ALBUM_ID;
        /** @var Album|null $album */
        $album = $this->get('models')->find(Album::class$albumId);

        if (!$album) {
            $this->View()->assign(['success' => false, 'message' => 'Invalid album id passed']);

            return;
        }

        
/** * This method prepares the media data for saving it directly to the blog model * * @param array $mediaData * * @return array */
    protected function prepareMediaDataForSaving($mediaData)
    {
        $mediaModels = [];
        foreach ($mediaData as $media) {
            $mediaModel = new Media();
            $media['media'] = $this->getManager()->find(\Shopware\Models\Media\Media::class$media['mediaId']);
            unset($media['mediaId']);
            $mediaModel->fromArray($media);
            $mediaModels[] = $mediaModel;
        }

        return $mediaModels;
    }

    /** * Helper method to delete all old tags mappings by the given blogId * * @param int $blogId */
/** * Creates a single media selection field. * * @param string $name * @param string $label * * @return Media */
    protected function createMediaField($name$label$defaultValue, array $options = [])
    {
        $element = new Media($name);
        $element->fromArray($options);
        $element->setLabel($label);
        $element->setDefaultValue($defaultValue);

        return $element;
    }

    /** * Creates a text field with an auto suffix `%` * * @param string $name * @param string $label * * @return Percent */
$this->attributeHydrator = $attributeHydrator;
        $this->thumbnailManager = $thumbnailManager;
        $this->mediaService = $mediaService;
        $this->connection = $connection;
    }

    /** * @return Media */
    public function hydrate(array $data)
    {
        $media = new Media();

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

        if (isset($data['__media_id'])) {
            $media->setId((int) $data['__media_id']);
        }

        if (isset($data['__media_name'])) {
            $media->setName($data['__media_name']);
        }

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