Skip to content
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

Closed
wants to merge 12 commits into from

Conversation

ellatrix
Copy link
Member

@ellatrix ellatrix commented Jul 19, 2019

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' ] where lock = true disables all operations. Thoughts?

The way the attributes are locked is by using the save function instead of the edit function. Decided to use edit, so it's guaranteed to exist. A prop isReadOnly will be passed down, so a block could disable attribute editing controls. Block controls that we provide, such as RichText, 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 adjust InnerBlocks.

Screenshots

Types of changes

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.

@ellatrix ellatrix added the [Feature] Templates API Related to API powering block template functionality in the Site Editor label Jul 19, 2019
@chrisvanpatten
Copy link
Contributor

Yes yes yes!

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' ] where lock = true disables all operations. Thoughts?

I agree completely! I actually have a few random proposals for this over in #8112. I think a more versatile option for templateLocking would be wildly useful.

@ellatrix
Copy link
Member Author

@chrisvanpatten Nice, I think that's what we should do then.

@ellatrix ellatrix force-pushed the try/template-read-only branch 2 times, most recently from 093e212 to 6a9cd7d Compare July 26, 2019 15:33
@chrisvanpatten
Copy link
Contributor

@ellatrix Is there anything I can do to help unblock/move this forward?

@ellatrix
Copy link
Member Author

Review? 🙂

@ellatrix
Copy link
Member Author

ellatrix commented Nov 27, 2019

I'll rebase the PR, but would be good to know if this is a good direction. Cc @mtias @epiqueras @mcsf.

@epiqueras
Copy link
Contributor

Yes, I think this array form of templateLock is much better and I like how we are still able to keep backwards compatibility with the string form and have our components infer the lock from their context.

- `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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `'move'` — prevents blocks form being moved.
- `'move'` — prevents blocks from being moved.

@mcsf
Copy link
Contributor

mcsf commented Jan 8, 2020

I'll rebase the PR, but would be good to know if this is a good direction

I think so, @ellatrix.

@richrd
Copy link

richrd commented May 21, 2020

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 templateLock: "all" but that still allows tabbing into the blocks within the slides. That causes all the edit controls to appear which breaks the slider layout.

I haven't found a solution yet but it looks like this PR would solve my problem 👍

@guarani
Copy link
Contributor

guarani commented Oct 27, 2020

Looks like this needs to be rebased with master and conflicts resolved to be testable on mobile since this PR pre-dates the monorepo changes.

@guarani guarani removed the request for review from cameronvoell October 27, 2020 17:41
Base automatically changed from master to trunk March 1, 2021 15:42
@guarani guarani removed their request for review February 7, 2022 18:51
@ellatrix ellatrix closed this Jul 18, 2022
@ellatrix ellatrix deleted the try/template-read-only branch July 18, 2022 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Templates API Related to API powering block template functionality in the Site Editor [Status] In Progress Tracking issues with work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants