prepareMediaData example

/** * @throws ValidationException * @throws Exception * * @return MediaModel */
    public function create(array $params)
    {
        $this->checkPrivilege('create');

        $params = $this->prepareMediaData($params);

        $media = new MediaModel();
        $media->fromArray($params);
        $attribute = new MediaAttribute();

        if (isset($params['attribute']) && \is_array($params['attribute'])) {
            $attribute->fromArray($params['attribute']);
        }
        $media->setAttribute($attribute);

        $path = $this->prepareFilePath($media->getPath()$media->getFileName());
        

    public function create(array $params)
    {
        $this->checkPrivilege('create');

        $manufacturer = new ManufacturerModel();

        $params = $this->prepareManufacturerData($params);
        $params = $this->prepareMediaData($params$manufacturer);

        $manufacturer->fromArray($params);

        if (isset($params['id'])) {
            $metaData = $this->getManager()->getMetadataFactory()->getMetadataFor(ManufacturerModel::class);
            $metaData->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_NONE);
            $manufacturer->setPrimaryIdentifier($params['id']);
        }

        $violations = $this->getManager()->validate($manufacturer);
        if ($violations->count() > 0) {
            

    public function create(array $params)
    {
        $this->checkPrivilege('create');

        $category = new CategoryModel();

        $params = $this->prepareCategoryData($params);
        $params = $this->prepareMediaData($params$category);
        $params = $this->prepareManualSorting($params$category);

        $category->fromArray($params);

        if (isset($params['id'])) {
            $metaData = $this->getManager()->getMetadataFactory()->getMetadataFor(CategoryModel::class);
            $metaData->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_NONE);
            $category->setPrimaryIdentifier($params['id']);
        }

        $violations = $this->getManager()->validate($category);
        
Home | Imprint | This part of the site doesn't use cookies.