From 44906e6038dd7a4a2de64cd406a1bd6ca4093f15 Mon Sep 17 00:00:00 2001 From: digital-brew Date: Sun, 3 Nov 2024 06:13:59 +0000 Subject: [PATCH] Add block icon, description, update category. --- composer.json | 3 ++- composer.lock | 11 ++++++----- src/Editor/AbstractBlock.php | 21 +++++++++++++++++++++ src/Providers/BlockServiceProvider.php | 25 +++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 869cb22..2a60470 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,8 @@ } ], "require": { - "php": "^8.1" + "php": "^8.1", + "ext-simplexml": "*" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index 1efccc8..78bf3d6 100644 --- a/composer.lock +++ b/composer.lock @@ -4,17 +4,18 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "36a593ada4dc90550267ae74afac64cd", + "content-hash": "bee635e90903964ddeac8728af1d8987", "packages": [], "packages-dev": [], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": {}, "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": "^8.1" + "php": "^8.1", + "ext-simplexml": "*" }, - "platform-dev": [], - "plugin-api-version": "2.2.0" + "platform-dev": {}, + "plugin-api-version": "2.6.0" } diff --git a/src/Editor/AbstractBlock.php b/src/Editor/AbstractBlock.php index 0ef59c8..173505d 100644 --- a/src/Editor/AbstractBlock.php +++ b/src/Editor/AbstractBlock.php @@ -24,6 +24,27 @@ class AbstractBlock */ public string $title = ''; + /** + * Block description + * + * @var string + */ + public string $description = ''; + + /** + * Block icon + * + * @var string + */ + public string $icon = 'block-default'; + + /** + * Block category + * + * @var string + */ + public string $category = 'common'; + /** * Block mame * diff --git a/src/Providers/BlockServiceProvider.php b/src/Providers/BlockServiceProvider.php index 26e5e27..04f26c2 100644 --- a/src/Providers/BlockServiceProvider.php +++ b/src/Providers/BlockServiceProvider.php @@ -7,6 +7,9 @@ use Illuminate\Support\ServiceProvider; use WP_Block_Type_Registry; +use function Roots\asset; + + class BlockServiceProvider extends ServiceProvider { /** @@ -115,6 +118,9 @@ public function enqueueBlockEditorAssets(): void $gutengood_blocks[] = (object) [ 'title' => $this->app[$block]->title, 'name' => $this->app[$block]->name, + 'description' => $this->app[$block]->description, + 'icon' => $this->getIcon($this->app[$block]->icon), + 'category' => $this->app[$block]->category, ]; } } @@ -171,4 +177,23 @@ public function registerMeta(): void }, $this->app[$block]->blockMeta()); } } + + /** + * Retrieve the block icon. + * + * @param $icon + * + * @return string + */ + public function getIcon($icon): string + { + if ( str_contains( $icon, ' $xml]; + + return json_encode($svg_obj); + } + + return $icon; + } }