Added an button to update a label profile from directly inside the label generator

Related to issue #994
This commit is contained in:
Jan Böhmer 2025-09-06 23:56:51 +02:00
parent a18ec373d2
commit 46d1a0cb1b
4 changed files with 50 additions and 1 deletions

View file

@ -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 !== []) {

View file

@ -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);
}
}

View file

@ -100,6 +100,8 @@
</div>
{% endif %}
{{ form_row(form.update_profile) }}
<div class="form-group row">
<div class="offset-sm-3 col-sm-9">
<div class="input-group">
@ -133,4 +135,4 @@
</object>
</div>
{% endif %}
{% endblock %}
{% endblock %}

View file

@ -13429,5 +13429,17 @@ Please note, that you can not impersonate a disabled user. If you try you will g
<target>Generic CSV</target>
</segment>
</unit>
<unit id=".N35Pvs" name="label_generator.update_profile">
<segment>
<source>label_generator.update_profile</source>
<target>Update profile with current settings</target>
</segment>
</unit>
<unit id="ulTo6Aa" name="label_generator.profile_updated">
<segment>
<source>label_generator.profile_updated</source>
<target>Label profile updated successfully.</target>
</segment>
</unit>
</file>
</xliff>