After having prefered to build classic themes for years (with good reason I’d say) I now about to dive deeper into the block-editor.
The kind of sites I mostly build need to get structured data and usually not a lot of ‘page building’ from editors that prefer a simple workflow. I accomplish this by using custom-post-types and (advanced-)custom-fields mostly.
Asthe classic-editor plugin starts to make more and more troubles (and feel more and more outdated) I am more or less forced to use the block-editor. (I#ve wored with it before, but without getting deeper into customizing/curating the editor/backend.)
More or less ever post, page etc, needs to have a simple set of meta-informatione (the department it belons to and one of four color-themes) I successfully built a block with advanced custom fields to collect this information, styled it and placed it om top of a template for posts.
functions.php
function register_basic_frame() {
$block_template = [
[ 'acf/institute', [
'lock' => [
'move' => true,
'remove' => true
]
] ],
[ 'core/group', [
'layout' => [
'type' => 'constrained',
],
'metadata' => [
'name' => 'Content',
],
'tagName' => 'section',
'allowedBlocks' => [
'core/paragraph',
'core/image'],
'lock' => [
'move' => true,
'remove' => true
],
'templateLock' => false, ],
[
['core/paragraph', [
'placeholder' => __('type here'),
]
]
],
]
];
$post_type_object = get_post_type_object( 'post' );
$post_type_object->template = $block_template;
$post_type_object->template_lock = 'insert';
}
What I wanted is to place the new block on top of every post, making it unmovable and undeletabe. After that I wanted to let the editor place whatever she likes (for now). I took me a lot of exerementiing to get this to work. I needed to make the template two parts on the first level, otherwise one was always able to move any block above my custom block. It is possible to place any active block inside the group-block.
So far so good, but what I don’t want is the Toolbar and the options in the Sidebar for that group to appear. I followed official tutorials to deregister the variations in the hope that at least that choice would disappear – it did not. The alignment and every other aspect of the content will be controlled by the theme and whatever the editor selects won’t have an infuence, so it is not only superfluous but also confusing to have those controlls. (I hid them with some CSS-trickery for the block I created, but I don’t think that this is a great option in general.)
I want all the red framed options in my screenshot gone.
I tried a lot of approaches, and read a lot of documentation and articles all over the web, but I’m still at a loss. Theme.json didn’t help as well as any hooks/filters I could find.
If there is a better over-all approach to achieve what I want I would be glad to hear about.
Maybe there is a super simple block like I would need out there?
I feel that there should be an option to disable every formatting controll for any block, by replacing them with defaults. But I cannot find any way to do so.
Also, as nice as the image-block functionallity is, I would need a version without it…
Can anyone point me in a helpful direction, or am I stuck with trying to build my own blocks from scrach?