Allow to download and view attachments via part info page.

This commit is contained in:
Jan Böhmer 2019-08-10 18:06:28 +02:00
parent 368645f0cb
commit 05fd753189
4 changed files with 202 additions and 2 deletions

View file

@ -29,6 +29,7 @@
namespace App\Services;
use App\Entity\Attachment;
use App\Entity\AttachmentType;
use App\Entity\Category;
use App\Entity\Device;
@ -82,11 +83,35 @@ class EntityURLGenerator
return $this->listPartsURL($entity);
case 'delete':
return $this->deleteURL($entity);
case 'file_download':
return $this->downloadURL($entity);
case 'file_view':
return $this->viewURL($entity);
}
throw new \InvalidArgumentException('Method is not supported!');
}
public function viewURL($entity) : string
{
if ($entity instanceof Attachment) {
return $this->urlGenerator->generate('attachment_view', ['id' => $entity->getID()]);
}
//Otherwise throw an error
throw new EntityNotSupported('The given entity is not supported yet!');
}
public function downloadURL($entity) : string
{
if ($entity instanceof Attachment) {
return $this->urlGenerator->generate('attachment_download', ['id' => $entity->getID()]);
}
//Otherwise throw an error
throw new EntityNotSupported('The given entity is not supported yet!');
}
/**
* Generates an URL to a page, where info about this entity can be viewed.
*