Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

70 rindas
2.0KB

  1. <?php
  2. namespace Lc\SovBundle\Form\Common;
  3. use ConnectHolland\CookieConsentBundle\Cookie\CookieChecker;
  4. use Symfony\Component\Form\AbstractTypeExtension;
  5. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  6. use Symfony\Component\Form\FormBuilderInterface;
  7. use ConnectHolland\CookieConsentBundle\Form\CookieConsentType as BaseCookieConsentType;
  8. class CookieConsentTypeExtension extends AbstractTypeExtension
  9. {
  10. /**
  11. * @var CookieChecker
  12. */
  13. protected $cookieChecker;
  14. /**
  15. * @var array
  16. */
  17. protected $cookieCategories;
  18. /**
  19. * @var bool
  20. */
  21. protected $cookieConsentSimplified;
  22. public function __construct(
  23. CookieChecker $cookieChecker,
  24. array $cookieCategories = [],
  25. bool $cookieConsentSimplified = null
  26. ) {
  27. $this->cookieChecker = $cookieChecker;
  28. $this->cookieCategories = $cookieCategories;
  29. $this->cookieConsentSimplified = $cookieConsentSimplified;
  30. }
  31. public function buildForm(FormBuilderInterface $builder, array $options)
  32. {
  33. foreach ($this->cookieCategories as $category) {
  34. $builder->remove($category);
  35. $data = 'true';
  36. if ($this->cookieChecker->isCookieConsentSavedByUser() && !$this->cookieChecker->isCategoryAllowedByUser(
  37. $category
  38. )) {
  39. $data = 'false';
  40. }
  41. $builder->add(
  42. $category,
  43. ChoiceType::class,
  44. [
  45. 'expanded' => true,
  46. 'multiple' => false,
  47. 'data' => $data,
  48. 'choices' => [
  49. ['ch_cookie_consent.yes' => 'true'],
  50. ['ch_cookie_consent.no' => 'false'],
  51. ],
  52. ]
  53. );
  54. }
  55. }
  56. public static function getExtendedTypes(): iterable
  57. {
  58. return [BaseCookieConsentType::class];
  59. }
  60. }