-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Template Locking: readonly / disable editing attributes #16678
Conversation
Yes yes yes!
I agree completely! I actually have a few random proposals for this over in #8112. I think a more versatile option for |
@chrisvanpatten Nice, I think that's what we should do then. |
093e212
to
6a9cd7d
Compare
055ee68
to
2aa7a0f
Compare
@ellatrix Is there anything I can do to help unblock/move this forward? |
Review? 🙂 |
I'll rebase the PR, but would be good to know if this is a good direction. Cc @mtias @epiqueras @mcsf. |
Yes, I think this array form of |
- `all` — prevents all operations. It is not possible to insert new blocks, move existing blocks, or delete blocks. | ||
- `insert` — prevents inserting or removing blocks, but allows moving existing blocks. | ||
- `'insert'` — prevents new blocks from being inserted. | ||
- `'move'` — prevents blocks form being moved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- `'move'` — prevents blocks form being moved. | |
- `'move'` — prevents blocks from being moved. |
I think so, @ellatrix. |
This would be great to have! I'm prototyping a slider block which needs to disable editing of the inner blocks when the slider is in preview mode. I tried I haven't found a solution yet but it looks like this PR would solve my problem 👍 |
Looks like this needs to be rebased with |
Description
This PR adds an option to the
<InnerBlocks>
templateLock
prop to disable all editing inside a template (block attributes).Unfortunately there is already an option
all
, which doesn't really locks all editing. It only disables block inserting, moving and removing.I'm not 100% sure if adding another option is the best thing. Perhaps we should have a prop that allows an array of allowed (or disallowed) operations. Something like
lock = [ 'insert', 'delete', 'move', 'attributes' ]
wherelock = true
disables all operations. Thoughts?The way the attributes are locked is by using theDecided to usesave
function instead of theedit
function.edit
, so it's guaranteed to exist. A propisReadOnly
will be passed down, so a block could disable attribute editing controls. Block controls that we provide, such asRichText
,PlainText
,Placeholder
etc. will be disabled by default. The block toolbar and inspector are aso disabled. To ensure so attributes get update by a block,setAttributes
will not do anything.How has this been tested?
Enable the CPT Locking test plugin. You should not be able to edit anything.
For further testing (with content) you could alter e.g. the group block's
edit
function and adjustInnerBlocks
.Screenshots
Types of changes
Checklist: