Closed davideprevosto closed 8 months ago
it is up to you. you can just delete the post type provider and use Poet instead if you want.
I am sorry to bore you with this topic again.
I tried to add the following filter:
add_filter('block_categories_all', function ($categories, $post) {
$myCategory = [
'slug' => 'my-category',
'title' => 'My Category',
'icon' => null,
];
$categories[] = $myCategory;
return($categories);
}, 10, 2);
...and I created a simple Block using Acorn.
The following templates (in the template $template array) are both custom blocks, using the same custom category:
acf/cta-slider
acf/community
<?php
declare(strict_types=1);
namespace App\Blocks\CombinedBlocks;
use Log1x\AcfComposer\Block;
use Log1x\AcfComposer\Builder;
use StoutLogic\AcfBuilder\FieldNameCollisionException;
class SliderWithCommunity extends Block
{
/**
* The block name.
*
* @var string
*/
public $name = 'Slider With Community';
/**
* The block view.
*
* @var string
*/
public $view = 'blocks.combined-blocks.slider-with-community';
/**
* The block description.
*
* @var string
*/
public $description = 'Slider With Community block.';
/**
* The block category.
*
* @var string
*/
public $category = 'my-category';
/**
* The block icon.
*
* @var string|array
*/
public $icon = 'editor-ul';
/**
* The block keywords.
*
* @var array
*/
public $keywords = [];
/**
* The block post type allow list.
*
* @var array
*/
public $post_types = [];
/**
* The parent block type allow list.
*
* @var array
*/
public $parent = [];
/**
* The ancestor block type allow list.
*
* @var array
*/
public $ancestor = [];
/**
* The default block mode.
*
* @var string
*/
public $mode = 'preview';
/**
* The default block alignment.
*
* @var string
*/
public $align = '';
/**
* The default block text alignment.
*
* @var string
*/
public $align_text = '';
/**
* The default block content alignment.
*
* @var string
*/
public $align_content = '';
/**
* The supported block features.
*
* @var array
*/
public $supports = [
'align' => true,
'align_text' => false,
'align_content' => false,
'full_height' => false,
'anchor' => false,
'mode' => false,
'multiple' => true,
'jsx' => true,
'color' => [
'background' => true,
'text' => true,
'gradient' => true,
],
];
/**
* The block styles.
*
* @var array
*/
public $styles = [];
/**
* The block preview example data.
*
* @var array
*/
public $example = [];
/**
* The block template.
*
* @var array
*/
public $template = [
'acf/cta-slider' => [],
'acf/community' => [],
];
/**
* Data to be passed to the block before rendering.
*
* @return array
*/
public function with(): array
{
return [];
}
/**
* The block field group.
*
* @return array
* @throws FieldNameCollisionException
*/
public function fields(): array
{
$sliderWithCommunity = Builder::make('slider_with_community');
$sliderWithCommunity
->addRepeater('items')
->addText('item')
->endRepeater();
return $sliderWithCommunity->build();
}
/**
* Assets enqueued when rendering the block.
*/
public function assets(array $block): void
{
//
}
}
Unfortunately I am not able to correctly load the custom category. I can see the default ones. Can you kindly suggest me a trick to try debugging this?
I have already run wp acorn acf:clear
and I am able to view my custom blocks running:
dd(\WP_Block_Type_Registry::get_instance()->get_all_registered())
My best
doesn't Radicle disable a bunch of block categories by default? i'd start there. otherwise, i'm afraid this is outside the scope of help with ACF Composer.
UPDATE and "SOLUTION": https://roots.io/radicle/docs/block-editor-plugins/#default-editor-plugin
Hello, I am using the
v3.0.23
version on a project withroots/radicle
.In the past I used the following code - in the
poet.php
(log1x/poet
) file - to add a custom blocks category:I wonder what is the best way to achieve the same result now.
Do I need to add a filter in the BlocksServiceProvider? Is it a right approach?
Thanks.