Browse Source

Intégration VichUploader pour l'image des zones

master
Guillaume 4 years ago
parent
commit
5372fad553
3 changed files with 30 additions and 3 deletions
  1. +2
    -1
      ShopBundle/Form/MerchantConfigType.php
  2. +0
    -1
      ShopBundle/Model/AbstractDocumentEntity.php
  3. +28
    -1
      ShopBundle/Model/MerchantConfig.php

+ 2
- 1
ShopBundle/Form/MerchantConfigType.php View File

use Symfony\Component\Form\FormEvents; use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Security\Core\Security; use Symfony\Component\Security\Core\Security;
use Vich\UploaderBundle\Form\Type\VichImageType;


class MerchantConfigType extends AbstractType class MerchantConfigType extends AbstractType
{ {
]); ]);
} }
elseif($merchantConfig->getFieldType() == 'image') { elseif($merchantConfig->getFieldType() == 'image') {
$form->add('value', CKFinderFileChooserType::class, [
$form->add('imageFile', VichImageType::class, [
'label' => $merchantConfig->getLabel(), 'label' => $merchantConfig->getLabel(),
]); ]);
} }

+ 0
- 1
ShopBundle/Model/AbstractDocumentEntity.php View File

use Lc\ShopBundle\Context\SluggableInterface; use Lc\ShopBundle\Context\SluggableInterface;
use Lc\ShopBundle\Context\SortableInterface; use Lc\ShopBundle\Context\SortableInterface;
use Lc\ShopBundle\Context\StatusInterface; use Lc\ShopBundle\Context\StatusInterface;
use Lc\ShopBundle\Model\AbstractEntity;
use Symfony\Component\HttpFoundation\File\File; use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich; use Vich\UploaderBundle\Mapping\Annotation as Vich;



+ 28
- 1
ShopBundle/Model/MerchantConfig.php View File

namespace Lc\ShopBundle\Model; namespace Lc\ShopBundle\Model;


use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;


/** /**
* @ORM\MappedSuperclass() * @ORM\MappedSuperclass()
* @Vich\Uploadable
*/ */
abstract class MerchantConfig
abstract class MerchantConfig extends AbstractEntity
{ {
/** /**
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\MerchantInterface", inversedBy="merchantConfigs") * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\MerchantInterface", inversedBy="merchantConfigs")
*/ */
protected $value; protected $value;


/**
* @Vich\UploadableField(mapping="images", fileNameProperty="value")
* @var File
*/
protected $imageFile;

public static $availableOptions = [] ; public static $availableOptions = [] ;


public function getMerchant(): ?Merchant public function getMerchant(): ?Merchant
return $this; return $this;
} }


public function setImageFile(File $image = null)
{
$this->imageFile = $image;

// VERY IMPORTANT:
// It is required that at least one field changes if you are using Doctrine,
// otherwise the event listeners won't be called and the file is lost
if ($image) {
// if 'updatedAt' is not defined in your entity, use another property
$this->updatedAt = new \DateTime('now');
}
}

public function getImageFile()
{
return $this->imageFile;
}

public static function getAvailableOptions(): array public static function getAvailableOptions(): array
{ {
return static::$availableOptions ; return static::$availableOptions ;

Loading…
Cancel
Save