From d02e0a8602d6dc6895f4f127e13189061728b31c Mon Sep 17 00:00:00 2001 From: Richard Dern Date: Tue, 23 Apr 2024 22:57:09 +0200 Subject: [PATCH] Allows to pass more options to attachment component --- app/Classes/AttachmentsManager.php | 8 ++++---- app/View/Components/BaseMediaComponent.php | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/Classes/AttachmentsManager.php b/app/Classes/AttachmentsManager.php index 029ffd3..cc7cc41 100644 --- a/app/Classes/AttachmentsManager.php +++ b/app/Classes/AttachmentsManager.php @@ -174,7 +174,7 @@ public function replaceAttachmentsInMarkdown(string $markdown) /** * Return a Blade component for the attachment we passed the ref off */ - public function getComponentByRef(string $ref, ?string $filter = null) + public function getComponentByRef(string $ref, ?string $filter, ?array $options = []) { $attachment = $this->getAttachmentData($ref); $variant = null; @@ -191,7 +191,7 @@ public function getComponentByRef(string $ref, ?string $filter = null) $variant['filename'] = $this->getVariantFullPath($ref, $filter); } - $component = $this->getBladeComponent($attachment, $variant); + $component = $this->getBladeComponent($attachment, $variant, $options); return $component; } @@ -343,11 +343,11 @@ private function getFormatedFilename(string $path): string * Return a Blade component corresponding to the kind of data we are * managing, and we pass it attachment data */ - private function getBladeComponent(array $data, ?array $variant = []) + private function getBladeComponent(array $data, ?array $variant, ?array $options = []) { switch ($this->kind) { case self::Images: - return new Image($data, $variant); + return new Image($data, $variant, $options); case self::Sounds: return new Sound($data); case self::Videos: diff --git a/app/View/Components/BaseMediaComponent.php b/app/View/Components/BaseMediaComponent.php index e92f5e9..e061c11 100644 --- a/app/View/Components/BaseMediaComponent.php +++ b/app/View/Components/BaseMediaComponent.php @@ -15,7 +15,7 @@ abstract class BaseMediaComponent extends Component /** * Create a new component instance. */ - public function __construct(protected array $data, protected ?array $variant = []) + public function __construct(protected array $data, protected ?array $variant = [], protected ?array $options = []) { } @@ -32,6 +32,7 @@ public function render(): View|Closure|string 'variantUrl' => $variantUrl, 'originalData' => $this->data, 'variantData' => $this->variant, + 'options' => $this->options, ]); }