diff --git a/DependencyInjection/ColinFreiBitFieldTypeExtension.php b/DependencyInjection/ColinFreiBitFieldTypeExtension.php deleted file mode 100644 index b22d5a3..0000000 --- a/DependencyInjection/ColinFreiBitFieldTypeExtension.php +++ /dev/null @@ -1,20 +0,0 @@ -load('services.xml'); - } -} diff --git a/Form/Type/BitfieldType.php b/Form/Type/BitfieldType.php index f440293..751786c 100644 --- a/Form/Type/BitfieldType.php +++ b/Form/Type/BitfieldType.php @@ -5,31 +5,36 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; +use Symfony\Component\OptionsResolver\OptionsResolver; use ColinFrei\BitFieldTypeBundle\Form\DataTransformer\BitfieldToArrayTransformer; class BitfieldType extends AbstractType { - public function getDefaultOptions(array $options) + /** + * {@inheritDoc} + */ + public function configureOptions(OptionsResolver $resolver) { - return array( + $resolver->setDefaults(array( 'expanded' => true, 'multiple' => true, - ); + )); } + /** + * {@inheritDoc} + */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->addModelTransformer(new BitfieldToArrayTransformer()); } + /** + * {@inheritDoc} + */ public function getParent() { - return new ChoiceType(); + return ChoiceType::class; } - - public function getName() - { - return 'bitfield'; - } -} \ No newline at end of file +} diff --git a/README.md b/README.md index ff04051..fe92241 100644 --- a/README.md +++ b/README.md @@ -19,12 +19,15 @@ Register the bundle in your app/AppKernel.php file, by adding this line in the ` ## Usage -Use the type `bitfield` when adding fields to the form, and pass in an array of options, like the type line in this example from the [Symfony documentation](http://symfony.com/doc/current/book/forms.html#building-the-form): +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](http://symfony.com/doc/current/book/forms.html#building-the-form): + use ColinFrei\BitFieldTypeBundle\Form\Type\BitfieldType; + $form = $this->createFormBuilder($task) ->add('task', 'text') ->add('dueDate', 'date') - ->add('type', 'bitfield', array( - 'choices' => array('1' => 'Annoying', '2' => 'Fun', '4' => 'Cool', '8' => 'Takes a while') + ->add('type', BitfieldType::class, array( + 'choices' => array('Annoying' => '1', 'Fun' => '2', 'Cool' => '4', 'Takes a while' => '8'), + 'choices_as_values' => true ) ->getForm(); \ No newline at end of file diff --git a/Resources/config/services.xml b/Resources/config/services.xml deleted file mode 100644 index fa33147..0000000 --- a/Resources/config/services.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - diff --git a/composer.json b/composer.json index 9a727b3..3a541aa 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "Adds a bitfield type to use in Symfony Forms", "license": "MIT", "require": { - "symfony/symfony": "~2.6" + "symfony/symfony": "~2.7" }, "authors": [ {