Show warning, if no valid entity was found to generate a label (don't throw an exception)

This commit is contained in:
Jan Böhmer 2020-05-05 19:55:31 +02:00
parent 5a9be023b1
commit c2db827c9d

View file

@ -108,8 +108,12 @@ class LabelController extends AbstractController
if (($form->isSubmitted() && $form->isValid()) || ($generate && !$form->isSubmitted() && $profile !== null)) { if (($form->isSubmitted() && $form->isValid()) || ($generate && !$form->isSubmitted() && $profile !== null)) {
$target_id = (string) $form->get('target_id')->getData(); $target_id = (string) $form->get('target_id')->getData();
$targets = $this->findObjects($form_options->getSupportedElement(), $target_id); $targets = $this->findObjects($form_options->getSupportedElement(), $target_id);
$pdf_data = $this->labelGenerator->generateLabel($form_options, $targets); if (!empty($targets)) {
$filename = $this->getLabelName($targets[0], $profile); $pdf_data = $this->labelGenerator->generateLabel($form_options, $targets);
$filename = $this->getLabelName($targets[0], $profile);
} else {
$this->addFlash('warning', 'label_generator.no_entities_found');
}
} }
return $this->render('LabelSystem/dialog.html.twig', [ return $this->render('LabelSystem/dialog.html.twig', [