From 1e616c449f063361db771a26f73da81c373ea4af Mon Sep 17 00:00:00 2001 From: Mart Kop Date: Thu, 5 Sep 2024 08:10:05 +0200 Subject: [PATCH] KUN-8981 | (fix) set internal as default option --- .../Form/DataTransformer/URLChooserToLinkTransformer.php | 5 +++-- .../NodeBundle/Form/Type/InternalURLSelectorType.php | 4 ++-- src/Kunstmaan/NodeBundle/Form/Type/URLChooserType.php | 2 +- src/Kunstmaan/NodeBundle/Form/Type/URLTypeType.php | 2 +- .../Resources/views/Form/formWidgets.html.twig | 9 ++++----- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Kunstmaan/NodeBundle/Form/DataTransformer/URLChooserToLinkTransformer.php b/src/Kunstmaan/NodeBundle/Form/DataTransformer/URLChooserToLinkTransformer.php index 302343f5b9..d4cc249d98 100644 --- a/src/Kunstmaan/NodeBundle/Form/DataTransformer/URLChooserToLinkTransformer.php +++ b/src/Kunstmaan/NodeBundle/Form/DataTransformer/URLChooserToLinkTransformer.php @@ -25,12 +25,13 @@ public function transform($value): array if ($value === null) { return [ - 'link_type' => URLChooserType::EXTERNAL, + 'link_type' => URLChooserType::INTERNAL, 'link_url' => null, ]; } $linkType = $this->getLinkType($value); + return array_merge($this->getChoiceOption($linkType, $value), [ 'link_type' => $linkType, 'link_url' => $value, @@ -72,7 +73,7 @@ private function getLinkType(mixed $value): string private function getChoiceOption(string $linkType, string $value): array { - return match($linkType) { + return match ($linkType) { URLChooserType::INTERNAL => ['choice_internal' => ['input' => $value]], URLChooserType::EXTERNAL => ['choice_external' => $value], URLChooserType::EMAIL => ['choice_email' => $value], diff --git a/src/Kunstmaan/NodeBundle/Form/Type/InternalURLSelectorType.php b/src/Kunstmaan/NodeBundle/Form/Type/InternalURLSelectorType.php index f783272c9d..502cadc9bd 100644 --- a/src/Kunstmaan/NodeBundle/Form/Type/InternalURLSelectorType.php +++ b/src/Kunstmaan/NodeBundle/Form/Type/InternalURLSelectorType.php @@ -11,7 +11,7 @@ class InternalURLSelectorType extends AbstractType { - public function buildForm(FormBuilderInterface $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options): void { $builder->add('input', HiddenType::class, [ 'label' => false, @@ -23,7 +23,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) ]); } - public function getBlockPrefix() + public function getBlockPrefix(): string { return 'internal_url_selector'; } diff --git a/src/Kunstmaan/NodeBundle/Form/Type/URLChooserType.php b/src/Kunstmaan/NodeBundle/Form/Type/URLChooserType.php index c396c7111e..666bbeb035 100644 --- a/src/Kunstmaan/NodeBundle/Form/Type/URLChooserType.php +++ b/src/Kunstmaan/NodeBundle/Form/Type/URLChooserType.php @@ -140,7 +140,7 @@ public function buildView(FormView $view, FormInterface $form, array $options) private function getLinkTypeExpression(string $type): string { - return 'this.getParent().get("link_type").getData() === "'.$type.'"'; + return 'this.getParent().get("link_type").getData() === "' . $type . '"'; } /** diff --git a/src/Kunstmaan/NodeBundle/Form/Type/URLTypeType.php b/src/Kunstmaan/NodeBundle/Form/Type/URLTypeType.php index f3b01eff9c..78a66245f8 100644 --- a/src/Kunstmaan/NodeBundle/Form/Type/URLTypeType.php +++ b/src/Kunstmaan/NodeBundle/Form/Type/URLTypeType.php @@ -19,7 +19,7 @@ public function configureOptions(OptionsResolver $resolver): void $resolver->setAllowedTypes('choices', 'array'); } - public function buildView(FormView $view, FormInterface $form, array $options) + public function buildView(FormView $view, FormInterface $form, array $options): void { $view->vars['choices'] = $options['choices']; } diff --git a/src/Kunstmaan/NodeBundle/Resources/views/Form/formWidgets.html.twig b/src/Kunstmaan/NodeBundle/Resources/views/Form/formWidgets.html.twig index 4c5b9d5b83..381bbdff56 100644 --- a/src/Kunstmaan/NodeBundle/Resources/views/Form/formWidgets.html.twig +++ b/src/Kunstmaan/NodeBundle/Resources/views/Form/formWidgets.html.twig @@ -60,17 +60,16 @@ - - + + {% else %} {% endif %} - {% else %} {% set linkUrl = form.link_url.vars %}