Skip to content

Commit

Permalink
Add block icon, description, update category.
Browse files Browse the repository at this point in the history
  • Loading branch information
digital-brew committed Nov 3, 2024
1 parent d4767f8 commit 44906e6
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 6 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
}
],
"require": {
"php": "^8.1"
"php": "^8.1",
"ext-simplexml": "*"
},
"autoload": {
"psr-4": {
Expand Down
11 changes: 6 additions & 5 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions src/Editor/AbstractBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
25 changes: 25 additions & 0 deletions src/Providers/BlockServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Illuminate\Support\ServiceProvider;
use WP_Block_Type_Registry;

use function Roots\asset;


class BlockServiceProvider extends ServiceProvider
{
/**
Expand Down Expand Up @@ -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,
];
}
}
Expand Down Expand Up @@ -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, '<svg' ) ) {
$xml = simplexml_load_string($icon);
$svg_obj = ['svg' => $xml];

return json_encode($svg_obj);
}

return $icon;
}
}

0 comments on commit 44906e6

Please sign in to comment.