The custom ReadOnly button was created to allow users to navigate away from the block editor instead of triggering the RichText control that you would typically get with a button.
We now want to move that injected content, into the page to allow admins to adjust the content which introduces the problem that there are 2 contexts in which the editor is being used.
Unauthenticated users
Site admins
This PR does the following:
IF URL contains wp-admin (ie: site admins editing the document to publish an update)
Use InnerBlock & a template to render a core/button as a child.
Else:
Render the InnerBlock content
Why this approach?
What I really wanted to do is include the default core/button block without using InnerBlock. I'm not sure how to do that or whether it's possible. I feel like it should be possible and I'm not thinking straight at the moment .🤷
Using it as an InnerBlock was the best second option because I don't want to have to create a custom button... But creating one is an alternative.
I don't like using the InnerBlock component because the InnerBlock.Content does not appear available when used within the Block Editor. Because of this, I was forced to dangerously inject the HTML content. I'm not certain it's dangerous in this context because the content would have to already be compromised.
This also isn't great because this only works when the template has 1 block. If we were to have multiple blocks in the template, it would not render all of the children properly because each block has originalContent that only includes content for the specific block.
Another alternative that was mentioned is just to let site admins edit as HTML. 🤔
The custom ReadOnly button was created to allow users to navigate away from the block editor instead of triggering the RichText control that you would typically get with a button.
We now want to move that injected content, into the page to allow admins to adjust the content which introduces the problem that there are 2 contexts in which the editor is being used.
This PR does the following:
wp-admin
(ie: site admins editing the document to publish an update)core/button
as a child.Why this approach?
What I really wanted to do is include the default
core/button
block without usingInnerBlock
. I'm not sure how to do that or whether it's possible. I feel like it should be possible and I'm not thinking straight at the moment .🤷Using it as an InnerBlock was the best second option because I don't want to have to create a custom button... But creating one is an alternative.
I don't like using the InnerBlock component because the
InnerBlock.Content
does not appear available when used within the Block Editor. Because of this, I was forced to dangerously inject the HTML content. I'm not certain it's dangerous in this context because the content would have to already be compromised.This also isn't great because this only works when the template has 1 block. If we were to have multiple blocks in the template, it would not render all of the children properly because each block has
originalContent
that only includes content for the specific block.Another alternative that was mentioned is just to let site admins edit as HTML. 🤔