From a46bcd229b6df2cfdb8b7f727578a94c95ce2363 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Thu, 11 Apr 2019 19:09:22 +0200 Subject: [PATCH] Allow to export all attachment_types via the new element dialog. --- src/Controller/AttachmentTypeController.php | 21 ++++++- .../AdminPages/EntityAdminBase.html.twig | 56 +++++++++++++++++++ 2 files changed, 75 insertions(+), 2 deletions(-) diff --git a/src/Controller/AttachmentTypeController.php b/src/Controller/AttachmentTypeController.php index cc9e1687..6a1d49d2 100644 --- a/src/Controller/AttachmentTypeController.php +++ b/src/Controller/AttachmentTypeController.php @@ -33,6 +33,7 @@ namespace App\Controller; use App\Entity\AttachmentType; +use App\Entity\NamedDBElement; use App\Entity\StructuralDBElement; use App\Form\BaseEntityAdminForm; use App\Form\ExportType; @@ -73,6 +74,7 @@ class AttachmentTypeController extends AbstractController /** * @Route("/new", name="attachment_type_new") + * @Route("/") * * @return \Symfony\Component\HttpFoundation\Response */ @@ -126,7 +128,7 @@ class AttachmentTypeController extends AbstractController } /** - * @Route("/export") + * @Route("/export", name="attachment_type_export_all") * @param Request $request * @param SerializerInterface $serializer * @param EntityManagerInterface $em @@ -198,7 +200,22 @@ class AttachmentTypeController extends AbstractController //If view option is not specified, then download the file. if (!$request->get('view')) { - $filename = "export_" . $entity->getName() . "_" . $level . "." . $format; + if ($entity instanceof NamedDBElement) { + $entity_name = $entity->getName(); + } elseif (is_array($entity)) { + if (empty($entity)) { + throw new \InvalidArgumentException('$entity must not be empty!'); + } + + //Use the class name of the first element for the filename + $reflection = new \ReflectionClass($entity[0]); + $entity_name = $reflection->getShortName(); + } else { + throw new \InvalidArgumentException('$entity type is not supported!'); + } + + + $filename = "export_" . $entity_name . "_" . $level . "." . $format; // Create the disposition of the file $disposition = $response->headers->makeDisposition( diff --git a/templates/AdminPages/EntityAdminBase.html.twig b/templates/AdminPages/EntityAdminBase.html.twig index ece4ea75..df91d72b 100644 --- a/templates/AdminPages/EntityAdminBase.html.twig +++ b/templates/AdminPages/EntityAdminBase.html.twig @@ -43,6 +43,8 @@ {% if entity.id %} + {% else %} + {% endif %} @@ -143,6 +145,60 @@ + {% else %} {# For new element we have a combined import/export tab #} +
+ + + +
+
+ {% trans %}export_all.label{% endtrans %} +
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+
+
+ + +
+
+
+ +
+
+ +
+
+
+
+
+ + {% endif %}