2017 © Pedro Peláez
 

symfony-bundle base64-bundle

/

image

tiloweb/base64-bundle

/

  • Friday, January 19, 2018
  • by Tiloweb
  • Repository
  • 2 Watchers
  • 2 Stars
  • 3,544 Installations
  • HTML
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 8 Versions
  • 12 % Grown

The README.md

Usage

This Bundle allow you to manage entities files send through your forms in base64., (*1)

Installation

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:, (*2)

$ composer require tiloweb/base64-bundle "dev-master"

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation., (*3)

Step 2: Enable the Bundle (only for Symfony 2 or 3)

Then, enable the bundle by adding it to the list of registered bundles in the app/AppKernel.php file of your project:, (*4)

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new Tiloweb\Base64Bundle\TilowebBase64Bundle(),
        );

        // ...
    }

    // ...
}

Step 3: Add the default twig theme

Add the default twig theme for the form in you app/config/config.yml for Symfony 2 and 3 app/config/packages/twig.yml for Symfony 4., (*5)

# app/config/config.yml

twig:
    form_themes:
        - '@TilowebBase64/form/fields.html.twig'

Step 4 : Configure your form type

<?php
// src/AppBundle/Form/ImageType.php

use App\Entity;
use Tiloweb\Base64Bundle\Form\Base64Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class ImageType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add("avatar", Base64Type::class, array(
                'label' => 'Avatar',
                'required' => false, // Can be true
                'deleteLabel' => 'Delete', // Optional if "required" is true, default : "Delete"
                'width' => 600, // Optionnal : If set, the image will be resized
                'height' => 400 // Optionnal : If not setted, the ratio will be respected, if setted with width, the image will be cropped.
            ))
        ;
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => Avatar::class,
        ));
    }
}

Step 5 : Enjoy !

Now, your form will show an file input. When you select an image, the preview is updated. If the field is not required, a "delete" button is shown. When the form is submited, you'll receive the base64 url of the image., (*6)

The Versions

19/01 2018

dev-master

9999999-dev

/

  Sources   Download

The Requires

 

bundle symfony3 image resize base64 tiloweb custom form type

19/01 2018

1.2.2

1.2.2.0

/

  Sources   Download

The Requires

 

bundle symfony3 image resize base64 tiloweb custom form type

18/11 2017

1.2.1

1.2.1.0

/

  Sources   Download

The Requires

 

bundle symfony3 image resize base64 tiloweb custom form type

07/09 2017

1.2

1.2.0.0

/

  Sources   Download

The Requires

 

bundle symfony3 image resize base64 tiloweb custom form type

07/09 2017

dev-crop

dev-crop

/

  Sources   Download

The Requires

 

bundle symfony3 image resize base64 tiloweb custom form type

06/09 2017

1.1

1.1.0.0

/

  Sources   Download

The Requires

 

bundle symfony3 image resize base64 tiloweb custom form type

28/07 2016

1.0.1

1.0.1.0

/

  Sources   Download

The Requires

 

bundle symfony3 image base64 tiloweb custom form type

26/07 2016

1.0

1.0.0.0

/

  Sources   Download

The Requires

 

bundle symfony3 image base64 tiloweb custom form type