<?php
namespace Cms\Modules\GalleryBundle\Form\Type;
use Common\Util\Base64;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\CallbackTransformer;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* Class GalleryEditorType
* @package Cms\Modules\GalleryBundle\Form\Type
*/
final class GalleryEditorType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildView(FormView $view, FormInterface $form, array $options)
{
$view->vars['params'] = array_merge(
array(
'baseHref' => $options['baseHref'],
'wscCustomerId' => $options['wscCustomerId'],
),
$options['modalParams']
);
}
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
// add transformer to go between base64 for browser and json for internal
$builder->addModelTransformer(
new CallbackTransformer(
function ($value) {
if (empty($value)) {
return null;
}
return Base64::webencode($value);
},
function ($value) {
if (empty($value)) {
return null;
}
return Base64::webdecode($value);
}
)
);
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setRequired(array(
'modalParams',
'baseHref',
'wscCustomerId',
));
}
/**
* {@inheritdoc}
*/
public function getParent(): ?string
{
return HiddenType::class;
}
}