colinfrei/bitfield-type-bundle

Adds a bitfield type to use in Symfony Forms

2.7.0 2018-07-17 06:13 UTC

This package is not auto-updated.

Last update: 2024-04-13 11:28:17 UTC


README

Installation

Add the following to your deps file:

[ColinFreiBitFieldFormTypeBundle]
    git=http://github.com/colinfrei/Symfony-Bitfield-Form-Type-Bundle.git
    target=bundles/ColinFrei/BitFieldTypeBundle

Register the ColinFrei namespace in the app/autoload.php file, by adding this line in the $loader->registerNamespaces(array( array:

'ColinFrei'        => __DIR__.'/../vendor/bundles',

Register the bundle in your app/AppKernel.php file, by adding this line in the bundles array in the registerBundles() function:

new ColinFrei\BitFieldTypeBundle\ColinFreiBitFieldTypeBundle(),

Usage

Use the BitfieldType class when adding fields to the form, and pass in an array of options, like the type line in this example from the Symfony documentation:

use ColinFrei\BitFieldTypeBundle\Form\Type\BitfieldType;

$form = $this->createFormBuilder($task)
    ->add('task', 'text')
    ->add('dueDate', 'date')
    ->add('type', BitfieldType::class, array(
        'choices' => array('Annoying' => '1', 'Fun' => '2', 'Cool' => '4', 'Takes a while' => '8'),
        'choices_as_values' => true
    )
    ->getForm();