trsteel88 / TrsteelCkeditorBundle

Symfony2 bundle for easy integration of the CKEditor WYSIWYG
97 stars 58 forks source link

Remove default required value #96

Closed wadjeroudi closed 9 years ago

wadjeroudi commented 9 years ago

The default required value should not be false and let the guesser auto guesses. Linked to #74.

trsteel88 commented 9 years ago

This has broken the tests. Also, changing the default value may affect some applications.

wadjeroudi commented 9 years ago

Ok, I understand.

For those who need to change this behavior, juste redefine the form type ckeditor:

<?php

namespace AppBundle\Form\Type;

use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use \Trsteel\CkeditorBundle\Form\Type\CkeditorType as BaseCkeditorType;

/**
 * Class CkeditorType
 * @package AppBundle\Form\Type
 */
class CkeditorType extends BaseCkeditorType
{
    /**
     * {@inheritdoc}
     */
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        /** @var OptionsResolver $resolver */
        $defaultRequired = $resolver->hasDefault('required');
        parent::setDefaultOptions($resolver);
        $resolver->setDefault('required', $defaultRequired);
    }

    /**
     * {@inheritdoc}
     */
    public function configureOptions(OptionsResolver $resolver)
    {
        $defaultRequired = $resolver->hasDefault('required');
        parent::configureOptions($resolver);
        $resolver->setDefault('required', $defaultRequired);
    }
}