xmon/color-picker-type-bundle

The ColorPickerTypeBundle extends Symfony2 form types, creates a new ColorPicker form type, to display a javascript color picker.

Installs: 31 713

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 2

Forks: 8

Open Issues: 7

Language:JavaScript

Type:symfony-bundle

v1.0.6 2017-06-16 08:36 UTC

This package is not auto-updated.

Last update: 2024-04-13 16:48:14 UTC


README

The ColorPickerTypeBundle extends Symfony2/3 form types, creates a new ColorPicker form type, to display a javascript color picker.

This Bundle use jscolor.

Installation

$ php composer.phar require xmon/color-picker-type-bundle

Add Bundle to your application kernel

// app/AppKernel.php
public function registerBundles()
{
    return array(
        // ...
        new Xmon\ColorPickerTypeBundle\XmonColorPickerTypeBundle(),
        // ...
    );
}

Configuration

Add ColorPickerTypeBundle to assetic

# app/config/config.yml
# Assetic Configuration
assetic:
    bundles:        [ 'XmonColorPickerTypeBundle' ]

[SYMFONY 2] Include the template for the layout.

You can modify the template in your own bundle.

# your config.yml
twig:
    form:
        resources:
            # This uses the default - you can put your own one here
            - 'XmonColorPickerTypeBundle:Form:fields.html.twig'

[SYMFONY 3] Include the template for the layout.

You can modify the template in your own bundle.

# your config.yml
twig:
    form_themes:
            # This uses the default - you can put your own one here
            - 'XmonColorPickerTypeBundle:Form:fields.html.twig'

Usage

Add validation to your model.

// src/AppBundle/Entity/MyEntity.php

use Symfony\Component\Validator\Constraints as Assert;
use Xmon\ColorPickerTypeBundle\Validator\Constraints as XmonAssertColor;

class MyEntity
{

    /**
     * @ORM\Column(type="string", length=6, nullable=true)
     * @XmonAssertColor\HexColor()
     */
    public $fieldName;

}

If you want change default message, try this:

    /**
     * @XmonAssertColor\HexColor(
     *      message = "Custom message for value (%color%)."
     * )
     */

[SYMFONY 2] How to use in your form.

$builder->add('fieldName', 'xmon_color_picker')

[SYMFONY 3] How to use in your form.

use Xmon\ColorPickerTypeBundle\Form\Type\ColorPickerType;
...
$builder->add('fieldName', ColorPickerType::class)
...

This form type can be used without any problem with SonataAdminBundle

Credits