mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-27 20:28:54 +02:00
Moved attachment form submit logic to a seperate service.
This commit is contained in:
parent
1f7c122ba2
commit
d382021fee
9 changed files with 279 additions and 73 deletions
|
@ -37,6 +37,7 @@ use App\Entity\UserSystem\User;
|
|||
use App\Form\AdminPages\ImportType;
|
||||
use App\Form\AdminPages\MassCreationForm;
|
||||
use App\Services\AttachmentHelper;
|
||||
use App\Services\Attachments\AttachmentSubmitHandler;
|
||||
use App\Services\EntityExporter;
|
||||
use App\Services\EntityImporter;
|
||||
use App\Services\StructuralElementRecursionHelper;
|
||||
|
@ -64,8 +65,10 @@ abstract class BaseAdminController extends AbstractController
|
|||
protected $passwordEncoder;
|
||||
protected $translator;
|
||||
protected $attachmentHelper;
|
||||
protected $attachmentSubmitHandler;
|
||||
|
||||
public function __construct(TranslatorInterface $translator, UserPasswordEncoderInterface $passwordEncoder, AttachmentHelper $attachmentHelper)
|
||||
public function __construct(TranslatorInterface $translator, UserPasswordEncoderInterface $passwordEncoder,
|
||||
AttachmentHelper $attachmentHelper, AttachmentSubmitHandler $attachmentSubmitHandler)
|
||||
{
|
||||
if ($this->entity_class === '' || $this->form_class === '' || $this->twig_template === '' || $this->route_base === '') {
|
||||
throw new \InvalidArgumentException('You have to override the $entity_class, $form_class, $route_base and $twig_template value in your subclasss!');
|
||||
|
@ -78,6 +81,7 @@ abstract class BaseAdminController extends AbstractController
|
|||
$this->translator = $translator;
|
||||
$this->passwordEncoder = $passwordEncoder;
|
||||
$this->attachmentHelper = $attachmentHelper;
|
||||
$this->attachmentSubmitHandler = $attachmentSubmitHandler;
|
||||
}
|
||||
|
||||
protected function _edit(NamedDBElement $entity, Request $request, EntityManagerInterface $em)
|
||||
|
@ -101,7 +105,7 @@ abstract class BaseAdminController extends AbstractController
|
|||
$attachments = $form['attachments'];
|
||||
foreach ($attachments as $attachment) {
|
||||
/** @var $attachment FormInterface */
|
||||
$this->attachmentHelper->upload( $attachment->getData(), $attachment['file']->getData());
|
||||
$this->attachmentSubmitHandler->handleFormSubmit($attachment->getData(), $attachment['file']->getData());
|
||||
}
|
||||
|
||||
$em->persist($entity);
|
||||
|
@ -146,7 +150,7 @@ abstract class BaseAdminController extends AbstractController
|
|||
$attachments = $form['attachments'];
|
||||
foreach ($attachments as $attachment) {
|
||||
/** @var $attachment FormInterface */
|
||||
$this->attachmentHelper->upload( $attachment->getData(), $attachment['file']->getData());
|
||||
$this->attachmentSubmitHandler->handleFormSubmit($attachment->getData(), $attachment['file']->getData());
|
||||
}
|
||||
|
||||
$em->persist($new_entity);
|
||||
|
|
|
@ -34,6 +34,7 @@ use App\Entity\Parts\Category;
|
|||
use App\Entity\Parts\Part;
|
||||
use App\Form\Part\PartBaseType;
|
||||
use App\Services\AttachmentHelper;
|
||||
use App\Services\Attachments\AttachmentSubmitHandler;
|
||||
use App\Services\Attachments\PartPreviewGenerator;
|
||||
use App\Services\PricedetailHelper;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
@ -81,7 +82,7 @@ class PartController extends AbstractController
|
|||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function edit(Part $part, Request $request, EntityManagerInterface $em, TranslatorInterface $translator,
|
||||
AttachmentHelper $attachmentHelper)
|
||||
AttachmentHelper $attachmentHelper, AttachmentSubmitHandler $attachmentSubmitHandler)
|
||||
{
|
||||
$this->denyAccessUnlessGranted('edit', $part);
|
||||
|
||||
|
@ -93,7 +94,7 @@ class PartController extends AbstractController
|
|||
$attachments = $form['attachments'];
|
||||
foreach ($attachments as $attachment) {
|
||||
/** @var $attachment FormInterface */
|
||||
$attachmentHelper->upload( $attachment->getData(), $attachment['file']->getData());
|
||||
$attachmentSubmitHandler->handleFormSubmit($attachment->getData(), $attachment['file']->getData());
|
||||
}
|
||||
|
||||
|
||||
|
@ -148,7 +149,7 @@ class PartController extends AbstractController
|
|||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function new(Request $request, EntityManagerInterface $em, TranslatorInterface $translator,
|
||||
AttachmentHelper $attachmentHelper)
|
||||
AttachmentHelper $attachmentHelper, AttachmentSubmitHandler $attachmentSubmitHandler)
|
||||
{
|
||||
$new_part = new Part();
|
||||
|
||||
|
@ -168,7 +169,7 @@ class PartController extends AbstractController
|
|||
$attachments = $form['attachments'];
|
||||
foreach ($attachments as $attachment) {
|
||||
/** @var $attachment FormInterface */
|
||||
$attachmentHelper->upload( $attachment->getData(), $attachment['file']->getData());
|
||||
$attachmentSubmitHandler->handleFormSubmit($attachment->getData(), $attachment['file']->getData());
|
||||
}
|
||||
|
||||
$em->persist($new_part);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue