diff --git a/src/Controller/LabelController.php b/src/Controller/LabelController.php index d0689330..8c0bcca0 100644 --- a/src/Controller/LabelController.php +++ b/src/Controller/LabelController.php @@ -88,6 +88,7 @@ class LabelController extends AbstractController $form = $this->createForm(LabelDialogType::class, null, [ 'disable_options' => $disable_options, + 'profile' => $profile ]); //Try to parse given target_type and target_id @@ -146,6 +147,29 @@ class LabelController extends AbstractController ]); } + if ($form->get('update_profile')->isClicked() && $profile instanceof LabelProfile && $this->isGranted('edit', $profile)) { //@phpstan-ignore-line Phpstan does not recognize the isClicked method + //Update the profile options + $profile->setOptions($form_options); + + //Validate the profile name + $errors = $this->validator->validate($profile); + if (count($errors) > 0) { + foreach ($errors as $error) { + $this->addFlash('error', $error->getMessage()); + } + goto render; + } + + $this->em->persist($profile); + $this->em->flush(); + $this->addFlash('success', 'label_generator.profile_updated'); + + return $this->redirectToRoute('label_dialog_profile', [ + 'profile' => $profile->getID(), + 'target_id' => (string) $form->get('target_id')->getData() + ]); + } + $target_id = (string) $form->get('target_id')->getData(); $targets = $this->findObjects($form_options->getSupportedElement(), $target_id); if ($targets !== []) { diff --git a/src/Form/LabelSystem/LabelDialogType.php b/src/Form/LabelSystem/LabelDialogType.php index f2710b19..d79d01f6 100644 --- a/src/Form/LabelSystem/LabelDialogType.php +++ b/src/Form/LabelSystem/LabelDialogType.php @@ -87,6 +87,16 @@ class LabelDialogType extends AbstractType ] ]); + if ($options['profile'] !== null) { + $builder->add('update_profile', SubmitType::class, [ + 'label' => 'label_generator.update_profile', + 'disabled' => !$this->security->isGranted('edit', $options['profile']), + 'attr' => [ + 'class' => 'btn btn-outline-success' + ] + ]); + } + $builder->add('update', SubmitType::class, [ 'label' => 'label_generator.update', ]); @@ -97,5 +107,6 @@ class LabelDialogType extends AbstractType parent::configureOptions($resolver); $resolver->setDefault('mapped', false); $resolver->setDefault('disable_options', false); + $resolver->setDefault('profile', null); } } diff --git a/templates/label_system/dialog.html.twig b/templates/label_system/dialog.html.twig index 50db99e7..571eb264 100644 --- a/templates/label_system/dialog.html.twig +++ b/templates/label_system/dialog.html.twig @@ -100,6 +100,8 @@ {% endif %} + {{ form_row(form.update_profile) }} +
@@ -133,4 +135,4 @@
{% endif %} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/translations/messages.en.xlf b/translations/messages.en.xlf index 888384da..41ad8358 100644 --- a/translations/messages.en.xlf +++ b/translations/messages.en.xlf @@ -13429,5 +13429,17 @@ Please note, that you can not impersonate a disabled user. If you try you will g Generic CSV + + + label_generator.update_profile + Update profile with current settings + + + + + label_generator.profile_updated + Label profile updated successfully. + +