Skip to content

Commit

Permalink
✨ Add support for using local SVG assets as block icons (Fixes #265) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Log1x authored Aug 12, 2024
1 parent 84faf1f commit c9402d4
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit c9402d4

Please sign in to comment.