src/Cms/Modules/GalleryBundle/Form/Type/GalleryEditorType.php line 18

Open in your IDE?
  1. <?php
  2. namespace Cms\Modules\GalleryBundle\Form\Type;
  3. use Common\Util\Base64;
  4. use Symfony\Component\Form\AbstractType;
  5. use Symfony\Component\Form\CallbackTransformer;
  6. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  7. use Symfony\Component\Form\FormBuilderInterface;
  8. use Symfony\Component\Form\FormInterface;
  9. use Symfony\Component\Form\FormView;
  10. use Symfony\Component\OptionsResolver\OptionsResolver;
  11. /**
  12.  * Class GalleryEditorType
  13.  * @package Cms\Modules\GalleryBundle\Form\Type
  14.  */
  15. final class GalleryEditorType extends AbstractType
  16. {
  17.     /**
  18.      * {@inheritdoc}
  19.      */
  20.     public function buildView(FormView $viewFormInterface $form, array $options)
  21.     {
  22.         $view->vars['params'] = array_merge(
  23.             array(
  24.                 'baseHref' => $options['baseHref'],
  25.                 'wscCustomerId' => $options['wscCustomerId'],
  26.             ),
  27.             $options['modalParams']
  28.         );
  29.     }
  30.     /**
  31.      * {@inheritdoc}
  32.      */
  33.     public function buildForm(FormBuilderInterface $builder, array $options)
  34.     {
  35.         // add transformer to go between base64 for browser and json for internal
  36.         $builder->addModelTransformer(
  37.             new CallbackTransformer(
  38.                 function ($value) {
  39.                     if (empty($value)) {
  40.                         return null;
  41.                     }
  42.                     return Base64::webencode($value);
  43.                 },
  44.                 function ($value) {
  45.                     if (empty($value)) {
  46.                         return null;
  47.                     }
  48.                     return Base64::webdecode($value);
  49.                 }
  50.             )
  51.         );
  52.     }
  53.     /**
  54.      * {@inheritdoc}
  55.      */
  56.     public function configureOptions(OptionsResolver $resolver)
  57.     {
  58.         $resolver->setRequired(array(
  59.             'modalParams',
  60.             'baseHref',
  61.             'wscCustomerId',
  62.         ));
  63.     }
  64.     /**
  65.      * {@inheritdoc}
  66.      */
  67.     public function getParent(): ?string
  68.     {
  69.         return HiddenType::class;
  70.     }
  71. }