|
8 | 8 | use C0ntax\ParsleyBundle\Contracts\ParsleyInterface; |
9 | 9 | use C0ntax\ParsleyBundle\Contracts\RemoveInterface; |
10 | 10 | use C0ntax\ParsleyBundle\Factory\ConstraintFactory; |
11 | | -use C0ntax\ParsleyBundle\Parsleys\Directive\Field\Generic; |
| 11 | +use C0ntax\ParsleyBundle\Parsleys\Directive\Field\Trigger; |
12 | 12 | use C0ntax\ParsleyBundle\Parsleys\RemoveParsleyConstraint; |
13 | 13 | use C0ntax\ParsleyBundle\Parsleys\RemoveSymfonyConstraint; |
14 | 14 | use Symfony\Component\Form\AbstractTypeExtension; |
@@ -214,16 +214,23 @@ private function getConstraintsFromForm(FormInterface $form): array |
214 | 214 | * @param FormView $view |
215 | 215 | * @param DirectiveInterface[] $directives |
216 | 216 | */ |
217 | | - private function addParsleyToView(FormView $view, array $directives) |
| 217 | + private function addParsleyToView(FormView $view, array $directives): void |
218 | 218 | { |
219 | 219 | $attr = []; |
220 | | - if (count($directives) > 0 && $this->getConfig()['field']['trigger'] !== null) { |
221 | | - $directives[] = new Generic('trigger', $this->getConfig()['field']['trigger']); |
222 | | - } |
223 | | - foreach ($directives as $constraint) { |
224 | | - foreach ($constraint->getViewAttr() as $key => $value) { |
| 220 | + $hasTrigger = false; |
| 221 | + |
| 222 | + foreach ($directives as $directive) { |
| 223 | + foreach ($directive->getViewAttr() as $key => $value) { |
225 | 224 | $attr[$key] = $value; |
226 | 225 | } |
| 226 | + if ($directive instanceof Trigger) { |
| 227 | + $hasTrigger = true; |
| 228 | + } |
| 229 | + } |
| 230 | + |
| 231 | + if (!$hasTrigger && count($directives) > 0 && $this->getConfig()['field']['trigger'] !== null) { |
| 232 | + $trigger = new Trigger($this->getConfig()['field']['trigger']); |
| 233 | + $attr = array_merge($attr, $trigger->getViewAttr()); |
227 | 234 | } |
228 | 235 |
|
229 | 236 | if (count($attr) > 0) { |
|
0 commit comments