mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-26 03:38:47 +02:00
Added possibillity to delete attachments in admin page.
This commit is contained in:
parent
72cd9a3722
commit
7c43feefbe
10 changed files with 133 additions and 19 deletions
|
@ -94,4 +94,29 @@ class AttachmentTypeController extends AbstractController
|
|||
'form' => $form->createView()
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/{id}", name="attachment_type_delete", methods={"DELETE"})
|
||||
*/
|
||||
public function delete(Request $request, AttachmentType $entity)
|
||||
{
|
||||
if ($this->isCsrfTokenValid('delete'.$entity->getId(), $request->request->get('_token'))) {
|
||||
$entityManager = $this->getDoctrine()->getManager();
|
||||
|
||||
$parent = $entity->getParent();
|
||||
|
||||
//Move all sub entities to the current parent
|
||||
foreach($entity->getSubelements() as $subelement) {
|
||||
$subelement->setParent($parent);
|
||||
$entityManager->persist($subelement);
|
||||
}
|
||||
|
||||
//Remove current element
|
||||
$entityManager->remove($entity);
|
||||
$entityManager->flush();
|
||||
$this->addFlash('success', 'attachment_type.deleted');
|
||||
}
|
||||
|
||||
return $this->redirectToRoute('attachment_type_new');
|
||||
}
|
||||
}
|
|
@ -73,6 +73,8 @@ class EntityURLGenerator
|
|||
case 'list':
|
||||
case 'list_parts':
|
||||
return $this->listPartsURL($entity);
|
||||
case 'delete':
|
||||
return $this->deleteURL($entity);
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException('Method is not supported!');
|
||||
|
@ -169,6 +171,15 @@ class EntityURLGenerator
|
|||
|
||||
}
|
||||
|
||||
public function deleteURL($entity) : string
|
||||
{
|
||||
if($entity instanceof AttachmentType) {
|
||||
return $this->urlGenerator->generate('attachment_type_delete', ['id' => $entity->getID()]);
|
||||
}
|
||||
|
||||
throw new EntityNotSupported('The given entity is not supported yet!');
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an HTML link to the info page about the given entity.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue