Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove all class attributes from CookieConsentType and put it inside the template. #107

Open
MichaelBrauner opened this issue Jan 13, 2022 · 1 comment

Comments

@MichaelBrauner
Copy link

I just wanted to change (interchange) the classes of the two (simplyfied) buttons. Since these are coded inside the options array of the form inside the builder I had to write a FormTypeExtension:

<?php

namespace App\Form\Extension;

use ConnectHolland\CookieConsentBundle\Form\CookieConsentType;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;

class CookieConsentTypeExtension extends AbstractTypeExtension
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->remove('use_only_functional_cookies');
        $builder->remove('use_all_cookies');

        $builder->add('use_only_functional_cookies', SubmitType::class, ['label' => 'ch_cookie_consent.use_only_functional_cookies', 'attr' => ['class' => 'btn ch-cookie-consent__btn ch-cookie-consent__btn--secondary']]);
        $builder->add('use_all_cookies', SubmitType::class, ['label' => 'ch_cookie_consent.use_all_cookies', 'attr' => ['class' => 'btn ch-cookie-consent__btn']]);
    }


    public static function getExtendedTypes(): iterable
    {
        return [CookieConsentType::class];
    }
}

Not that this was hard or so - but I think, it would be much cleaner when classes are set ONLY inside the templates for easy overwriting. Not in two different places.

If you want I can open a pull request for that. If it's welcome?

@MichaelBrauner
Copy link
Author

Ah I see. Inside the template it would be kind of messy to conditionaly attach it inside the for loop.
Hm, what do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant