1 | <?php |
||||
2 | |||||
3 | /* |
||||
4 | * @copyright 2014 Mautic Contributors. All rights reserved |
||||
5 | * @author Mautic |
||||
6 | * |
||||
7 | * @link http://mautic.org |
||||
8 | * |
||||
9 | * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html |
||||
10 | */ |
||||
11 | |||||
12 | namespace Mautic\PluginBundle\Form\Type; |
||||
13 | |||||
14 | use Mautic\CoreBundle\Form\Type\FormButtonsType; |
||||
15 | use Mautic\CoreBundle\Form\Type\StandAloneButtonType; |
||||
16 | use Mautic\CoreBundle\Form\Type\YesNoButtonGroupType; |
||||
17 | use Mautic\PluginBundle\Entity\Integration; |
||||
18 | use Symfony\Component\Form\AbstractType; |
||||
19 | use Symfony\Component\Form\Extension\Core\Type\ChoiceType; |
||||
20 | use Symfony\Component\Form\Extension\Core\Type\HiddenType; |
||||
21 | use Symfony\Component\Form\FormBuilderInterface; |
||||
22 | use Symfony\Component\Form\FormEvent; |
||||
23 | use Symfony\Component\Form\FormEvents; |
||||
24 | use Symfony\Component\OptionsResolver\OptionsResolver; |
||||
25 | |||||
26 | /** |
||||
27 | * Class DetailsType. |
||||
28 | */ |
||||
29 | class DetailsType extends AbstractType |
||||
30 | { |
||||
31 | /** |
||||
32 | * {@inheritdoc} |
||||
33 | */ |
||||
34 | public function buildForm(FormBuilderInterface $builder, array $options) |
||||
35 | { |
||||
36 | $builder->add('isPublished', YesNoButtonGroupType::class); |
||||
37 | |||||
38 | $formSettings = $options['integration_object']->getFormDisplaySettings(); |
||||
39 | if ($keys = $options['integration_object']->getRequiredKeyFields()) { |
||||
40 | $decryptedKeys = $options['integration_object']->decryptApiKeys($options['data']->getApiKeys()); |
||||
41 | |||||
42 | if (!empty($formSettings['hide_keys'])) { |
||||
43 | foreach ($formSettings['hide_keys'] as $key) { |
||||
44 | unset($keys[$key]); |
||||
45 | } |
||||
46 | } |
||||
47 | |||||
48 | $builder->add( |
||||
49 | 'apiKeys', |
||||
50 | KeysType::class, |
||||
51 | [ |
||||
52 | 'label' => false, |
||||
53 | 'integration_keys' => $keys, |
||||
54 | 'data' => $decryptedKeys, |
||||
55 | 'integration_object' => $options['integration_object'], |
||||
56 | ] |
||||
57 | ); |
||||
58 | |||||
59 | $builder->addEventListener( |
||||
60 | FormEvents::PRE_SUBMIT, |
||||
61 | function (FormEvent $event) use ($keys, $decryptedKeys, $options) { |
||||
62 | $data = $event->getData(); |
||||
63 | $form = $event->getForm(); |
||||
64 | |||||
65 | $form->add( |
||||
66 | 'apiKeys', |
||||
67 | KeysType::class, |
||||
68 | [ |
||||
69 | 'label' => false, |
||||
70 | 'integration_keys' => $keys, |
||||
71 | 'data' => $decryptedKeys, |
||||
72 | 'integration_object' => $options['integration_object'], |
||||
73 | 'is_published' => (int) $data['isPublished'], |
||||
74 | ] |
||||
75 | ); |
||||
76 | } |
||||
77 | ); |
||||
78 | |||||
79 | if (!empty($formSettings['requires_authorization'])) { |
||||
80 | $disabled = false; |
||||
81 | $label = ($options['integration_object']->isAuthorized()) ? 'reauthorize' : 'authorize'; |
||||
82 | |||||
83 | $builder->add( |
||||
84 | 'authButton', |
||||
85 | StandAloneButtonType::class, |
||||
86 | [ |
||||
87 | 'attr' => [ |
||||
88 | 'class' => 'btn btn-success btn-lg', |
||||
89 | 'onclick' => 'Mautic.initiateIntegrationAuthorization()', |
||||
90 | 'icon' => 'fa fa-key', |
||||
91 | ], |
||||
92 | 'label' => 'mautic.integration.form.'.$label, |
||||
93 | 'disabled' => $disabled, |
||||
94 | ] |
||||
95 | ); |
||||
96 | } |
||||
97 | } |
||||
98 | |||||
99 | $features = $options['integration_object']->getSupportedFeatures(); |
||||
100 | $tooltips = $options['integration_object']->getSupportedFeatureTooltips(); |
||||
101 | if (!empty($features)) { |
||||
102 | // Check to see if the integration is a new entry and thus not configured |
||||
103 | $configured = null !== $options['data']->getId(); |
||||
104 | $enabledFeatures = $options['data']->getSupportedFeatures(); |
||||
105 | $data = ($configured) ? $enabledFeatures : $features; |
||||
106 | |||||
107 | $choices = []; |
||||
108 | foreach ($features as $f) { |
||||
109 | $choices['mautic.integration.form.feature.'.$f] = $f; |
||||
110 | } |
||||
111 | |||||
112 | $builder->add( |
||||
113 | 'supportedFeatures', |
||||
114 | ChoiceType::class, |
||||
115 | [ |
||||
116 | 'choices' => $choices, |
||||
117 | 'expanded' => true, |
||||
118 | 'label_attr' => ['class' => 'control-label'], |
||||
119 | 'multiple' => true, |
||||
120 | 'label' => 'mautic.integration.form.features', |
||||
121 | 'required' => false, |
||||
122 | 'data' => $data, |
||||
123 | 'choice_attr' => function ($val, $key, $index) use ($tooltips) { |
||||
0 ignored issues
–
show
The parameter
$key is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||
124 | if (array_key_exists($val, $tooltips)) { |
||||
125 | return [ |
||||
126 | 'data-toggle' => 'tooltip', |
||||
127 | 'title' => $tooltips[$val], |
||||
128 | ]; |
||||
129 | } else { |
||||
130 | return []; |
||||
131 | } |
||||
132 | }, |
||||
133 | ] |
||||
134 | ); |
||||
135 | } |
||||
136 | |||||
137 | $builder->add( |
||||
138 | 'featureSettings', |
||||
139 | FeatureSettingsType::class, |
||||
140 | [ |
||||
141 | 'label' => 'mautic.integration.form.feature.settings', |
||||
142 | 'required' => true, |
||||
143 | 'data' => $options['data']->getFeatureSettings(), |
||||
144 | 'label_attr' => ['class' => 'control-label'], |
||||
145 | 'integration' => $options['integration'], |
||||
146 | 'integration_object' => $options['integration_object'], |
||||
147 | 'lead_fields' => $options['lead_fields'], |
||||
148 | 'company_fields' => $options['company_fields'], |
||||
149 | ] |
||||
150 | ); |
||||
151 | |||||
152 | $builder->add('name', HiddenType::class, ['data' => $options['integration']]); |
||||
153 | |||||
154 | $builder->add('in_auth', HiddenType::class, ['mapped' => false]); |
||||
155 | |||||
156 | $builder->add('buttons', FormButtonsType::class); |
||||
157 | |||||
158 | if (!empty($options['action'])) { |
||||
159 | $builder->setAction($options['action']); |
||||
160 | } |
||||
161 | |||||
162 | $options['integration_object']->modifyForm($builder, $options); |
||||
163 | } |
||||
164 | |||||
165 | /** |
||||
166 | * {@inheritdoc} |
||||
167 | */ |
||||
168 | public function configureOptions(OptionsResolver $resolver) |
||||
169 | { |
||||
170 | $resolver->setDefaults( |
||||
171 | [ |
||||
172 | 'data_class' => Integration::class, |
||||
173 | ] |
||||
174 | ); |
||||
175 | |||||
176 | $resolver->setRequired(['integration', 'integration_object', 'lead_fields', 'company_fields']); |
||||
177 | } |
||||
178 | |||||
179 | /** |
||||
180 | * {@inheritdoc} |
||||
181 | */ |
||||
182 | public function getBlockPrefix() |
||||
183 | { |
||||
184 | return 'integration_details'; |
||||
185 | } |
||||
186 | } |
||||
187 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.