From c9402d44b2adf3ef28bd0b077105afc580f28f70 Mon Sep 17 00:00:00 2001 From: Brandon Date: Mon, 12 Aug 2024 06:43:24 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20support=20for=20using=20local?= =?UTF-8?q?=20SVG=20assets=20as=20block=20icons=20(Fixes=20#265)=20(#277)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Block.php | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/Block.php b/src/Block.php index e7c9451b..93b10f0e 100644 --- a/src/Block.php +++ b/src/Block.php @@ -9,6 +9,8 @@ use Log1x\AcfComposer\Concerns\InteractsWithBlade; use Log1x\AcfComposer\Contracts\Block as BlockContract; +use function Roots\asset; + abstract class Block extends Composer implements BlockContract { use FormatsCss, InteractsWithBlade; @@ -407,6 +409,28 @@ public function getTextDomain(): string ?? 'acf-composer'; } + /** + * Retrieve the block icon. + */ + public function getIcon(): string|array + { + if (is_array($this->icon)) { + return $this->icon; + } + + if (Str::startsWith($this->icon, 'asset:')) { + $asset = Str::of($this->icon) + ->after('asset:') + ->before('.svg') + ->replace('.', '/') + ->finish('.svg'); + + return asset($asset)->contents(); + } + + return $this->icon; + } + /** * Handle the block template. */ @@ -485,7 +509,7 @@ public function settings(): Collection 'title' => $this->name, 'description' => $this->description, 'category' => $this->category, - 'icon' => $this->icon, + 'icon' => $this->getIcon(), 'keywords' => $this->keywords, 'parent' => $this->parent ?: null, 'ancestor' => $this->ancestor ?: null,