-
Notifications
You must be signed in to change notification settings - Fork 10
/
SettingValueType.php
98 lines (87 loc) · 3.14 KB
/
SettingValueType.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
namespace Lexxpavlov\SettingsBundle\Form\Type;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextType;
class SettingValueType extends AbstractType
{
/** @var ContainerInterface */
private $container;
/** @var string */
private $htmlWidget;
/**
* @param ContainerInterface $container
* @param string $htmlWidget
*/
public function __construct(ContainerInterface $container, $htmlWidget)
{
$this->container = $container;
$this->htmlWidget = $htmlWidget;
}
public function buildView(FormView $view, FormInterface $form, array $options)
{
$choiceViewClass = Kernel::MAJOR_VERSION == 2 && Kernel::MINOR_VERSION == 6
? 'Symfony\Component\Form\Extension\Core\View\ChoiceView'
: 'Symfony\Component\Form\ChoiceList\View\ChoiceView';
$choiceList = array(
new $choiceViewClass('off', 'off', "Off"),
new $choiceViewClass('on', 'on', "On"),
);
$view->vars = array_replace($view->vars, array(
'required' => false,
'multiple' => false,
'expanded' => false,
'empty_data' => null,
'attr' => array('data-lexxpavlov-settings'=>'true', 'data-sonata-select2'=>'false'),
'preferred_choices' => null,
'choices' => $choiceList,
'choice_translation_domain' => 'messages',
'placeholder' => null,
'html_widget' => $this->htmlWidget,
));
if ($this->htmlWidget == 'ckeditor') {
if ($this->container->has('ivory_ck_editor.form.type')) {
$resolver = new OptionsResolver();
$builder = $this->container->get('form.factory')->createBuilder();
$ckeditorType = $this->container->get('ivory_ck_editor.form.type');
if (method_exists($ckeditorType, 'configureOptions')) {
$ckeditorType->configureOptions($resolver);
} else {
$ckeditorType->setDefaultOptions($resolver);
}
$ckeditorType->buildForm($builder, $resolver->resolve());
$ckeditorType->buildView($view, $builder->getForm(), []);
} else {
$view->vars = array_replace($view->vars, array(
'base_path' => $this->container->getParameter('lexxpavlov_settings.ckeditor.base_path'),
'js_path' => $this->container->getParameter('lexxpavlov_settings.ckeditor.js_path'),
));
}
}
}
/**
* {@inheritdoc}
*/
public function getParent()
{
return TextType::class;
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->getBlockPrefix();
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'setting_value';
}
}