Added possibillity to delete attachments in admin page.

This commit is contained in:
Jan Böhmer 2019-04-06 18:38:36 +02:00
parent 72cd9a3722
commit 7c43feefbe
10 changed files with 133 additions and 19 deletions

View file

@ -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');
}
}

View file

@ -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.
*