1414use MauticPlugin \MauticSqlConditionsBundle \Validator \Constraint \UrlDnsConstraint ;
1515use Symfony \Component \Form \AbstractType ;
1616use Symfony \Component \Form \FormBuilderInterface ;
17+ use Symfony \Component \OptionsResolver \OptionsResolver ;
18+ use Symfony \Component \Routing \RouterInterface ;
1719use Symfony \Component \Validator \Constraints \NotBlank ;
1820
1921class SqlConditionsCampaignType extends AbstractType
2022{
23+ /**
24+ * @var RouterInterface
25+ */
26+ protected $ router ;
27+
28+ /**
29+ * @param RouterInterface $router
30+ */
31+ public function __construct (RouterInterface $ router )
32+ {
33+ $ this ->router = $ router ;
34+ }
35+
36+
2137 /**
2238 * @param FormBuilderInterface $builder
2339 * @param array $options
@@ -29,13 +45,89 @@ public function buildForm(FormBuilderInterface $builder, array $options)
2945 'sql ' ,
3046 SqlListType::class,
3147 [
32- 'label ' => 'mautic.sqlConditions.sql ' ,
33- 'label_attr ' => ['class ' => 'control-label ' ],
34- 'attr ' => ['class ' => 'form-control ' ],
48+ 'label ' => 'mautic.sqlConditions.sql ' ,
49+ 'label_attr ' => ['class ' => 'control-label ' ],
50+ 'attr ' => [
51+ 'class ' => 'form-control ' ,
52+ 'onchange ' => 'Mautic.disabledSqlConditionsActions() ' ,
53+ ],
54+ 'multiple ' => false ,
55+ 'required ' => true ,
3556 'constraints ' => [
3657 new NotBlank (),
3758 ],
3859 ]
3960 );
61+
62+
63+
64+ if (!empty ($ options ['update_select ' ])) {
65+ $ windowUrl = $ this ->router ->generate (
66+ 'mautic_sqlConditions_action ' ,
67+ [
68+ 'objectAction ' => 'new ' ,
69+ 'contentOnly ' => 1 ,
70+ 'updateSelect ' => $ options ['update_select ' ],
71+ ]
72+ );
73+
74+ $ builder ->add (
75+ 'newButton ' ,
76+ 'button ' ,
77+ [
78+ 'attr ' => [
79+ 'class ' => 'btn btn-primary btn-nospin ' ,
80+ 'onclick ' => 'Mautic.loadNewWindow({
81+ "windowUrl": " ' .$ windowUrl .'"
82+ }) ' ,
83+ 'icon ' => 'fa fa-plus ' ,
84+ ],
85+ 'label ' => 'mautic.core.form.add ' ,
86+ ]
87+ );
88+
89+ // create button edit focus
90+ $ windowUrlEdit = $ this ->router ->generate (
91+ 'mautic_sqlConditions_action ' ,
92+ [
93+ 'objectAction ' => 'edit ' ,
94+ 'objectId ' => 'objectId ' ,
95+ 'contentOnly ' => 1 ,
96+ 'updateSelect ' => $ options ['update_select ' ],
97+ ]
98+ );
99+
100+ $ builder ->add (
101+ 'editButton ' ,
102+ 'button ' ,
103+ [
104+ 'attr ' => [
105+ 'class ' => 'btn btn-primary btn-nospin ' ,
106+ 'onclick ' => 'Mautic.loadNewWindow(Mautic.standardSqlConditionsUrl({"windowUrl": " ' .$ windowUrlEdit .'"})) ' ,
107+ 'disabled ' => !isset ($ options ['data ' ]['sql ' ]),
108+ 'icon ' => 'fa fa-edit ' ,
109+ ],
110+ 'label ' => 'mautic.core.form.edit ' ,
111+ ]
112+ );
113+ }
114+
115+ }
116+
117+
118+ /**
119+ * @param OptionsResolver $resolver
120+ */
121+ public function configureOptions (OptionsResolver $ resolver )
122+ {
123+ $ resolver ->setDefined (['update_select ' ]);
124+ }
125+
126+ /**
127+ * @return string
128+ */
129+ public function getName ()
130+ {
131+ return 'sqlconditions_list ' ;
40132 }
41133}
0 commit comments