Use twig global AttachmentManager in templates.

This commit is contained in:
Jan Böhmer 2020-04-03 14:56:48 +02:00
parent 6b99784238
commit 2dd807bbe6
4 changed files with 7 additions and 16 deletions

View file

@ -81,7 +81,6 @@ abstract class BaseAdminController extends AbstractController
protected $passwordEncoder; protected $passwordEncoder;
protected $translator; protected $translator;
protected $attachmentHelper;
protected $attachmentSubmitHandler; protected $attachmentSubmitHandler;
protected $commentHelper; protected $commentHelper;
@ -90,7 +89,7 @@ abstract class BaseAdminController extends AbstractController
protected $dataTableFactory; protected $dataTableFactory;
public function __construct(TranslatorInterface $translator, UserPasswordEncoderInterface $passwordEncoder, public function __construct(TranslatorInterface $translator, UserPasswordEncoderInterface $passwordEncoder,
AttachmentManager $attachmentHelper, AttachmentSubmitHandler $attachmentSubmitHandler, AttachmentSubmitHandler $attachmentSubmitHandler,
EventCommentHelper $commentHelper, HistoryHelper $historyHelper, TimeTravel $timeTravel, EventCommentHelper $commentHelper, HistoryHelper $historyHelper, TimeTravel $timeTravel,
DataTableFactory $dataTableFactory) DataTableFactory $dataTableFactory)
{ {
@ -108,7 +107,6 @@ abstract class BaseAdminController extends AbstractController
$this->translator = $translator; $this->translator = $translator;
$this->passwordEncoder = $passwordEncoder; $this->passwordEncoder = $passwordEncoder;
$this->attachmentHelper = $attachmentHelper;
$this->attachmentSubmitHandler = $attachmentSubmitHandler; $this->attachmentSubmitHandler = $attachmentSubmitHandler;
$this->commentHelper = $commentHelper; $this->commentHelper = $commentHelper;
$this->historyHelper = $historyHelper; $this->historyHelper = $historyHelper;
@ -206,7 +204,6 @@ abstract class BaseAdminController extends AbstractController
return $this->render($this->twig_template, [ return $this->render($this->twig_template, [
'entity' => $entity, 'entity' => $entity,
'form' => $form->createView(), 'form' => $form->createView(),
'attachment_helper' => $this->attachmentHelper,
'route_base' => $this->route_base, 'route_base' => $this->route_base,
'datatable' => $table, 'datatable' => $table,
'timeTravel' => $timeTravel_timestamp, 'timeTravel' => $timeTravel_timestamp,
@ -322,7 +319,6 @@ abstract class BaseAdminController extends AbstractController
'form' => $form->createView(), 'form' => $form->createView(),
'import_form' => $import_form->createView(), 'import_form' => $import_form->createView(),
'mass_creation_form' => $mass_creation_form->createView(), 'mass_creation_form' => $mass_creation_form->createView(),
'attachment_helper' => $this->attachmentHelper,
'route_base' => $this->route_base, 'route_base' => $this->route_base,
]); ]);
} }

View file

@ -76,15 +76,13 @@ use Symfony\Contracts\Translation\TranslatorInterface;
*/ */
class PartController extends AbstractController class PartController extends AbstractController
{ {
protected $attachmentManager;
protected $pricedetailHelper; protected $pricedetailHelper;
protected $partPreviewGenerator; protected $partPreviewGenerator;
protected $commentHelper; protected $commentHelper;
public function __construct(AttachmentManager $attachmentManager, PricedetailHelper $pricedetailHelper, public function __construct(PricedetailHelper $pricedetailHelper,
PartPreviewGenerator $partPreviewGenerator, EventCommentHelper $commentHelper) PartPreviewGenerator $partPreviewGenerator, EventCommentHelper $commentHelper)
{ {
$this->attachmentManager = $attachmentManager;
$this->pricedetailHelper = $pricedetailHelper; $this->pricedetailHelper = $pricedetailHelper;
$this->partPreviewGenerator = $partPreviewGenerator; $this->partPreviewGenerator = $partPreviewGenerator;
$this->commentHelper = $commentHelper; $this->commentHelper = $commentHelper;
@ -136,7 +134,6 @@ class PartController extends AbstractController
[ [
'part' => $part, 'part' => $part,
'datatable' => $table, 'datatable' => $table,
'attachment_helper' => $this->attachmentManager,
'pricedetail_helper' => $this->pricedetailHelper, 'pricedetail_helper' => $this->pricedetailHelper,
'pictures' => $this->partPreviewGenerator->getPreviewAttachments($part), 'pictures' => $this->partPreviewGenerator->getPreviewAttachments($part),
'timeTravel' => $timeTravel_timestamp, 'timeTravel' => $timeTravel_timestamp,
@ -194,7 +191,6 @@ class PartController extends AbstractController
[ [
'part' => $part, 'part' => $part,
'form' => $form->createView(), 'form' => $form->createView(),
'attachment_helper' => $this->attachmentManager,
]); ]);
} }
@ -231,7 +227,7 @@ class PartController extends AbstractController
* @return Response * @return Response
*/ */
public function new(Request $request, EntityManagerInterface $em, TranslatorInterface $translator, public function new(Request $request, EntityManagerInterface $em, TranslatorInterface $translator,
AttachmentManager $attachmentHelper, AttachmentSubmitHandler $attachmentSubmitHandler, ?Part $part = null): Response AttachmentSubmitHandler $attachmentSubmitHandler, ?Part $part = null): Response
{ {
if (null === $part) { if (null === $part) {
$new_part = new Part(); $new_part = new Part();
@ -318,7 +314,6 @@ class PartController extends AbstractController
[ [
'part' => $new_part, 'part' => $new_part,
'form' => $form->createView(), 'form' => $form->createView(),
'attachment_helper' => $attachmentHelper,
]); ]);
} }
} }

View file

@ -22,7 +22,7 @@
{# @var attach \App\Entity\Attachments\Attachment #} {# @var attach \App\Entity\Attachments\Attachment #}
{% if attachment_helper.fileExisting(attach) %} {% if attachment_manager.fileExisting(attach) %}
{% if not attach.external %} {% if not attach.external %}
<br><br> <br><br>
<h6> <h6>
@ -31,7 +31,7 @@
</span> </span>
<br> <br>
<span class="badge badge-secondary"> <span class="badge badge-secondary">
<i class="fas fa-hdd fa-fw"></i> {{ attachment_helper.humanFileSize(attach) }} <i class="fas fa-hdd fa-fw"></i> {{ attachment_manager.humanFileSize(attach) }}
</span> </span>
</h6> </h6>
{% else %} {% else %}

View file

@ -19,7 +19,7 @@
{% set attach = attachment.vars.value %} {% set attach = attachment.vars.value %}
{% if attachment_helper.fileExisting(attach) %} {% if attachment_manager.fileExisting(attach) %}
{% if not attach.external %} {% if not attach.external %}
<br><br> <br><br>
<h6> <h6>
@ -28,7 +28,7 @@
</span> </span>
<br> <br>
<span class="badge badge-secondary"> <span class="badge badge-secondary">
<i class="fas fa-hdd fa-fw"></i> {{ attachment_helper.humanFileSize(attach) }} <i class="fas fa-hdd fa-fw"></i> {{ attachment_manager.humanFileSize(attach) }}
</span> </span>
</h6> </h6>
{% else %} {% else %}