Skip to content

Commit 46d1a0c

Browse files
committed
Added an button to update a label profile from directly inside the label generator
Related to issue #994
1 parent a18ec37 commit 46d1a0c

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

src/Controller/LabelController.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public function generator(Request $request, ?LabelProfile $profile = null): Resp
8888

8989
$form = $this->createForm(LabelDialogType::class, null, [
9090
'disable_options' => $disable_options,
91+
'profile' => $profile
9192
]);
9293

9394
//Try to parse given target_type and target_id
@@ -146,6 +147,29 @@ public function generator(Request $request, ?LabelProfile $profile = null): Resp
146147
]);
147148
}
148149

150+
if ($form->get('update_profile')->isClicked() && $profile instanceof LabelProfile && $this->isGranted('edit', $profile)) { //@phpstan-ignore-line Phpstan does not recognize the isClicked method
151+
//Update the profile options
152+
$profile->setOptions($form_options);
153+
154+
//Validate the profile name
155+
$errors = $this->validator->validate($profile);
156+
if (count($errors) > 0) {
157+
foreach ($errors as $error) {
158+
$this->addFlash('error', $error->getMessage());
159+
}
160+
goto render;
161+
}
162+
163+
$this->em->persist($profile);
164+
$this->em->flush();
165+
$this->addFlash('success', 'label_generator.profile_updated');
166+
167+
return $this->redirectToRoute('label_dialog_profile', [
168+
'profile' => $profile->getID(),
169+
'target_id' => (string) $form->get('target_id')->getData()
170+
]);
171+
}
172+
149173
$target_id = (string) $form->get('target_id')->getData();
150174
$targets = $this->findObjects($form_options->getSupportedElement(), $target_id);
151175
if ($targets !== []) {

src/Form/LabelSystem/LabelDialogType.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,16 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
8787
]
8888
]);
8989

90+
if ($options['profile'] !== null) {
91+
$builder->add('update_profile', SubmitType::class, [
92+
'label' => 'label_generator.update_profile',
93+
'disabled' => !$this->security->isGranted('edit', $options['profile']),
94+
'attr' => [
95+
'class' => 'btn btn-outline-success'
96+
]
97+
]);
98+
}
99+
90100
$builder->add('update', SubmitType::class, [
91101
'label' => 'label_generator.update',
92102
]);
@@ -97,5 +107,6 @@ public function configureOptions(OptionsResolver $resolver): void
97107
parent::configureOptions($resolver);
98108
$resolver->setDefault('mapped', false);
99109
$resolver->setDefault('disable_options', false);
110+
$resolver->setDefault('profile', null);
100111
}
101112
}

templates/label_system/dialog.html.twig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@
100100
</div>
101101
{% endif %}
102102

103+
{{ form_row(form.update_profile) }}
104+
103105
<div class="form-group row">
104106
<div class="offset-sm-3 col-sm-9">
105107
<div class="input-group">
@@ -133,4 +135,4 @@
133135
</object>
134136
</div>
135137
{% endif %}
136-
{% endblock %}
138+
{% endblock %}

translations/messages.en.xlf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13429,5 +13429,17 @@ Please note, that you can not impersonate a disabled user. If you try you will g
1342913429
<target>Generic CSV</target>
1343013430
</segment>
1343113431
</unit>
13432+
<unit id=".N35Pvs" name="label_generator.update_profile">
13433+
<segment>
13434+
<source>label_generator.update_profile</source>
13435+
<target>Update profile with current settings</target>
13436+
</segment>
13437+
</unit>
13438+
<unit id="ulTo6Aa" name="label_generator.profile_updated">
13439+
<segment>
13440+
<source>label_generator.profile_updated</source>
13441+
<target>Label profile updated successfully.</target>
13442+
</segment>
13443+
</unit>
1343213444
</file>
1343313445
</xliff>

0 commit comments

Comments
 (0)