Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add support for using local SVG assets as block icons (Fixes #265) #277

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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