Sfoglia il codice sorgente

Intégration VichUploader pour l'image des zones

master
Guillaume 4 anni fa
parent
commit
5372fad553
3 ha cambiato i file con 30 aggiunte e 3 eliminazioni
  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 Vedi File

@@ -15,6 +15,7 @@ use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Security\Core\Security;
use Vich\UploaderBundle\Form\Type\VichImageType;

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

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

@@ -7,7 +7,6 @@ use Gedmo\Mapping\Annotation as Gedmo;
use Lc\ShopBundle\Context\SluggableInterface;
use Lc\ShopBundle\Context\SortableInterface;
use Lc\ShopBundle\Context\StatusInterface;
use Lc\ShopBundle\Model\AbstractEntity;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;


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

@@ -3,11 +3,14 @@
namespace Lc\ShopBundle\Model;

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

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

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

public static $availableOptions = [] ;

public function getMerchant(): ?Merchant
@@ -63,6 +72,24 @@ abstract class MerchantConfig
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
{
return static::$availableOptions ;

Loading…
Annulla
Salva