diff --git a/EMS/admin-ui-bundle/assets/js/core/helpers/ckeditor5-link/src/ui/linkactionsview.js b/EMS/admin-ui-bundle/assets/js/core/helpers/ckeditor5-link/src/ui/linkactionsview.js index a73a2df5d..5ea7840f1 100644 --- a/EMS/admin-ui-bundle/assets/js/core/helpers/ckeditor5-link/src/ui/linkactionsview.js +++ b/EMS/admin-ui-bundle/assets/js/core/helpers/ckeditor5-link/src/ui/linkactionsview.js @@ -146,7 +146,7 @@ export default class LinkActionsView extends View { 'ck-link-actions__preview' ], href: bind.to('href', href => self._getEmsUrl(href)), - target: '_blank', + target: bind.to('href', href => href.startsWith('#') ? '' : '_blank'), rel: 'noopener noreferrer' } }) diff --git a/EMS/admin-ui-bundle/assets/js/core/plugins/select.js b/EMS/admin-ui-bundle/assets/js/core/plugins/select.js index ce318dd75..3a295b9ab 100644 --- a/EMS/admin-ui-bundle/assets/js/core/plugins/select.js +++ b/EMS/admin-ui-bundle/assets/js/core/plugins/select.js @@ -21,11 +21,13 @@ class Select { } select2 (target) { - $(target).find('select.select2').select2({ + const targetQuery = $(target) + targetQuery.find('select.select2').select2({ theme: 'bootstrap-5', allowClear: true, placeholder: '', - escapeMarkup: function (markup) { return markup } + escapeMarkup: function (markup) { return markup }, + dropdownParent: targetQuery }) } } diff --git a/EMS/admin-ui-bundle/src/Resources/views/bootstrap5/core/link-modal.html.twig b/EMS/admin-ui-bundle/src/Resources/views/bootstrap5/core/link-modal.html.twig index 652de620f..3e890bab4 100644 --- a/EMS/admin-ui-bundle/src/Resources/views/bootstrap5/core/link-modal.html.twig +++ b/EMS/admin-ui-bundle/src/Resources/views/bootstrap5/core/link-modal.html.twig @@ -3,8 +3,8 @@ diff --git a/EMS/admin-ui-bundle/src/Resources/views/bootstrap5/modal/link.html.twig b/EMS/admin-ui-bundle/src/Resources/views/bootstrap5/modal/link.html.twig index ee4a3b7c3..68f8a5280 100644 --- a/EMS/admin-ui-bundle/src/Resources/views/bootstrap5/modal/link.html.twig +++ b/EMS/admin-ui-bundle/src/Resources/views/bootstrap5/modal/link.html.twig @@ -1 +1,12 @@ -{{ form(form) }} \ No newline at end of file +{% trans_default_domain 'ems-adminui-twigs' %} +{{ form_start(form) }} + {{ form_errors(form) }} + {% for field in form.children|filter(f => f.vars.name != 'submit') %} + {{ form_row(field) }} + {% endfor %} +
+ {{ form_widget(form.submit) }} + +
+{{ form_end(form) }} + diff --git a/EMS/core-bundle/src/Form/Form/AnchorChoiceLoader.php b/EMS/core-bundle/src/Form/Form/AnchorChoiceLoader.php new file mode 100644 index 000000000..f0dd54074 --- /dev/null +++ b/EMS/core-bundle/src/Form/Form/AnchorChoiceLoader.php @@ -0,0 +1,35 @@ +choices)) { + return; + } + $label = $anchor; + if (\str_starts_with($label, '#')) { + $label = \substr($label, 1); + } + $this->choices = \array_merge([$label => $anchor], $this->choices); + } + + /** + * @return array + */ + protected function loadChoices(): iterable + { + return $this->choices; + } +} diff --git a/EMS/core-bundle/src/Form/Form/LoadLinkModalType.php b/EMS/core-bundle/src/Form/Form/LoadLinkModalType.php index 062ff9739..bed7957df 100644 --- a/EMS/core-bundle/src/Form/Form/LoadLinkModalType.php +++ b/EMS/core-bundle/src/Form/Form/LoadLinkModalType.php @@ -3,6 +3,7 @@ namespace EMS\CoreBundle\Form\Form; use EMS\CoreBundle\EMSCoreBundle; +use EMS\CoreBundle\Entity\Form\LoadLinkModalEntity; use EMS\CoreBundle\Form\Field\FileType; use EMS\CoreBundle\Form\Field\ObjectPickerType; use EMS\CoreBundle\Form\Field\SubmitEmsType; @@ -15,6 +16,8 @@ use Symfony\Component\Form\Extension\Core\Type\TextareaType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\Form\FormInterface; +use Symfony\Component\Form\FormView; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Validator\Constraints\Email; @@ -38,6 +41,7 @@ class LoadLinkModalType extends AbstractType public const FIELD_SUBMIT = 'submit'; public const WITH_TARGET_BLANK_FIELD = 'with_target_blank_field'; public const ANCHOR_TARGETS = 'anchor_targets'; + private AnchorChoiceLoader $anchorLoader; public function __construct(private readonly RouterInterface $router) { @@ -49,6 +53,7 @@ public function __construct(private readonly RouterInterface $router) */ public function buildForm(FormBuilderInterface $builder, array $options): void { + $this->anchorLoader = new AnchorChoiceLoader($options[self::ANCHOR_TARGETS]); $builder ->add(self::FIELD_LINK_TYPE, ChoiceType::class, [ 'label' => 'link_modal.field.link_type', @@ -148,7 +153,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ->add(self::FIELD_ANCHOR, ChoiceType::class, [ 'label' => 'link_modal.field.anchor', 'attr' => ['data-tags' => true, 'class' => 'select2'], - 'choices' => $options[self::ANCHOR_TARGETS], + 'choice_loader' => $this->anchorLoader, 'multiple' => false, 'choice_translation_domain' => false, 'required' => false, @@ -162,6 +167,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ]]), ], ]); + $builder->get(self::FIELD_ANCHOR)->resetViewTransformers(); if (true === ($options[self::WITH_TARGET_BLANK_FIELD] ?? false)) { $builder->add(self::FIELD_TARGET_BLANK, CheckboxType::class, [ @@ -204,4 +210,13 @@ public function configureOptions(OptionsResolver $resolver): void ]); parent::configureOptions($resolver); } + + public function buildView(FormView $view, FormInterface $form, array $options): void + { + $data = $options['data'] ?? null; + if ($data instanceof LoadLinkModalEntity and null !== $anchor = $data->getAnchor()) { + $this->anchorLoader->addAnchor($anchor); + } + parent::buildView($view, $form, $options); + } }