Skip to content

Commit 7767155

Browse files
committed
Fail gracefully, when an exception occurs during rendering of the example labels for label profiles
This fixes issue #671
1 parent e231404 commit 7767155

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Controller/AdminPages/BaseAdminController.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
use App\Entity\LabelSystem\LabelProfile;
3636
use App\Entity\Parameters\AbstractParameter;
3737
use App\Exceptions\AttachmentDownloadException;
38+
use App\Exceptions\TwigModeException;
3839
use App\Form\AdminPages\ImportType;
3940
use App\Form\AdminPages\MassCreationForm;
4041
use App\Repository\AbstractPartsContainingRepository;
@@ -53,6 +54,7 @@
5354
use Omines\DataTablesBundle\DataTableFactory;
5455
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
5556
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
57+
use Symfony\Component\Form\FormError;
5658
use Symfony\Component\Form\FormInterface;
5759
use Symfony\Component\HttpFoundation\File\UploadedFile;
5860
use Symfony\Component\HttpFoundation\RedirectResponse;
@@ -211,7 +213,12 @@ protected function _edit(AbstractNamedDBElement $entity, Request $request, Entit
211213
//Show preview for LabelProfile if needed.
212214
if ($entity instanceof LabelProfile) {
213215
$example = $this->barcodeExampleGenerator->getElement($entity->getOptions()->getSupportedElement());
214-
$pdf_data = $this->labelGenerator->generateLabel($entity->getOptions(), $example);
216+
$pdf_data = null;
217+
try {
218+
$pdf_data = $this->labelGenerator->generateLabel($entity->getOptions(), $example);
219+
} catch (TwigModeException $exception) {
220+
$form->get('options')->get('lines')->addError(new FormError($exception->getMessage()));
221+
}
215222
}
216223

217224
/** @var AbstractPartsContainingRepository $repo */

0 commit comments

Comments
 (0)