2017 © Pedro Peláez
 

symfony-bundle sonata-image-bundle

Allow easy support for image upload in sonata forms with preview of current image in onetoone relation

image

zenside/sonata-image-bundle

Allow easy support for image upload in sonata forms with preview of current image in onetoone relation

  • Friday, March 17, 2017
  • by janel-nicolas
  • Repository
  • 1 Watchers
  • 0 Stars
  • 54 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 2 Open issues
  • 1 Versions
  • 2 % Grown

The README.md

ZenSide Sonata Image Bundle

Allow to easyly add Image property to an entity to be included in Sonata Forms., (*1)

Installation

Add bundle with composer, (*2)

composer require zenside/sonata-image-bundle

And reference it in AppKernel.php, (*3)

new ZenSide\SonataImageBundle\ZenSideSonataImageBundle(),

Configuration

After downloaded and add to AppKernel the bundle, update your database to add Image entity, (*4)

php app/console doctrine:schema:update --force

Then you can add relations to Image type in your entities, (*5)

class Article {
    /**
     * @ORM\OneToOne(targetEntity="ZenSide\SonataImageBundle\Entity\Image", cascade={"persist"})
     * @ORM\JoinColumn(nullable=true, onDelete="set null")
     */
    private $image;
}

If you want to directly use it in a SonataAdmin class, just use the field with type 'sonata_type_admin' or 'sonata_type_model', (*6)

$form->add('logo', 'sonata_type_admin');

Important : if you use 'sonata_type_admin' to directly include input type file in your form, you have to add the following preUpdate and prePersist listeners in your Admin class., (*7)

Just copy the following lines in your Admin class :, (*8)

public function prePersist($subject)
{
    ImageAdmin::manageEmbeddedImageAdmins($this, $subject);
}
public function preUpdate($subject)
{
    ImageAdmin::manageEmbeddedImageAdmins($this, $subject);
}

The Versions

17/03 2017

dev-master

9999999-dev

Allow easy support for image upload in sonata forms with preview of current image in onetoone relation

  Sources   Download

GPL-3.0+

The Requires