new text editor block that contains core blocks as inner blocks and prevents them from being used at top level

This commit is contained in:
2025-11-27 07:14:31 +00:00
parent 00d0861014
commit 0055a25420
17 changed files with 218 additions and 45 deletions

View File

@@ -11,7 +11,10 @@
<div class="section-{{ $block['name'] }}-inner">
<div class="container{{ @$data['container_width'] ? ' container-' . $data['container_width'] : '' }} block-content wysiwyg">
<InnerBlocks allowedBlocks="{!! esc_attr( wp_json_encode( $data['allowed_blocks'] ) ) !!}" />
<InnerBlocks
allowedBlocks="{!! esc_attr( wp_json_encode( $data['allowed_blocks'] ) ) !!}"
template="{!! esc_attr( wp_json_encode( $data['template'] ) ) !!}"
/>
</div>
</div>

View File

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 40 KiB

View File

@@ -1,10 +1,10 @@
<?php
namespace Blocks\Content;
namespace Blocks\Editor;
use App\Utilities;
use App\ACF;
class Content
class Editor
{
public function __construct()
{
@@ -14,12 +14,12 @@ class Content
public function init()
{
acf_register_block_type([
'name' => 'badegg/content',
'title' => __('Content'),
'description' => __('Wordpress blocks inside a wrapper'),
'name' => 'badegg-editor',
'title' => __('Text Editor'),
'description' => __('Long form text content with support for things like headings, lists, and images.'),
'render_callback' => [ $this, 'render'],
'category' => 'badegg',
'icon' => 'columns',
'icon' => 'media-document',
'supports' => [
'align' => false,
'jsx' => true,
@@ -67,6 +67,7 @@ class Content
$data = array_merge($data, $block);
$data['section_classes'] = $CssClasses->section($data);
$data['allowed_blocks'] = $this->inner_blocks();
$data['template'] = $this->default_template();
$data['block'] = $block;
echo \Roots\view("blocks.$name.$name", [
@@ -75,6 +76,31 @@ class Content
])->render();
}
public function default_template()
{
return [
[
'core/heading',
[
'level' => 1,
'placeholder' => 'Heading',
],
],
[
'core/paragraph',
[
'placeholder' => 'You can type your own text, change the heading level, or delete it altogether. You can also type over this text.',
],
],
[
'core/paragraph',
[
'placeholder' => 'To adjust block settings, click the Text Editor icon floating above this block to display them in the sidebar.',
],
],
];
}
public function inner_blocks()
{
return [