-
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
More versatile templateLock #8112
Comments
This is a great idea! I agree that |
Per an earlier conversation with @youknowriad and @jorgefilipecosta on Slack, I wrote up a few use-cases for some of the currently-not-possible functions that this new API would bring. I focussed on why it would be helpful to split Another important note: I think, to understand the value in this proposed API, it's essential to think about Without further blathering on… Why would you need to disallow
|
I'm interested in taking a crack at this and just wondering what the API should look like. Perhaps getTemplateLock(block.clientId).can('delete') This would be useful too because it would make it easy to build in back-compat. Also realising that if this is renamed to something more vague like |
Discussed in today's Core Editor chat: https://wordpress.slack.com/archives/C02QB2JS7/p1534340662000100 |
@chrisvanpatten I am interested in collaborating with you on this task, as I have an instance where this functionality would prove useful. Is the expectation that this functionality would also extend to Please let me know if/how you want to connect and collaborate on tackling this issue. |
@kopepasah To be quite honest my schedule is pretty tight at the moment :( I still think there's a lot of merit to this proposal, but I'm not sure I can be the one to tackle it right now, unfortunately. If it's something you think you are up for though, I'd be happy to offer any support I can! |
Going to put this in the |
I'm also interested in this feature. Right now the template lock is not fine-grained enough for me: I need to lock some blocks completely and only allow some blocks in others (which are contained in the completely locked block...). I did notice that if I lock a block template that includes a variable-block template, the input looks correct but after saving all content disappears. Also, if I lock an entire content type template and then add columns, none of the columns are locked. Somewhere – preferably in the same file or admin page – I need to be able to define ALL of the blocks in my template and for each one which blocks are allowed in it. The best example I've seen for setting up this kind of scenario is the ACF flexible layout builder. |
I'm just revisiting this issue and I still think it merits further discussion and potentially a solution. In general, I think InnerBlocks has some awesome opportunities but some of the mechanics could be improved. The case of disabling |
I support all of what @chrisvanpatten has said about making
However, the slideshow block example would be better handled (IMO) by changes to how block (and CPT) templates are specified. I've been thinking about open an issue about this, but will comment here for now: I think it would be helpful if block (and CPT) templates were able to specify cardinality (i.e., min/maxOccurs) for the blocks in the template. |
I keep running into this problem and it's increasingly frustrating. In particular, the fact that an However as I think about it, I wonder if — in the interest of backward compatibility — it might make sense to replace Something like… <InnerBlocks
allowInsert={ false }
allowMove={ true }
allowDelete={ false }
/> These could then be manipulated independently, and ultimately |
This issue that I'm closing as a duplicate has a similar idea, but suggests even more granular control of block insertion, and being able to restrict insertion to before or after a template only: (cc @anUserFr) |
This is definitely very important. I'd appreciate some feedback on this comment I left on a different issue which is pretty related: #11681 (comment) |
TLDR: since global template validation runs different code than InnerBlocks template validation, it's hard to fix bugs or make enhancements to how block templates work. What if, instead, validation happened at the BlockList level? |
When talking about these restrictions it's fundamental to separate the modification of the interface & interactions from what relates to validating that a block tree matches a specification. This is important because restricting the interface doesn't really enforce any data structure — you could edit the source and change the order, remove elements, and so on, and This issue, for example, is related to what @jorgefilipecosta is working on about enabling or disabling specific UI elements. It'd be good to model them together because they overlap: #18173 An API of It should also be fine to do things like allowing a Separately, I think |
I'm wondering how the two interact. For example, if I have a template lock all on the InnerBlocks, should that influence the |
I 1000% agree with your comment @mtias, and in fact this is how we have moved to address the problem within my organization (admittedly using hacky CSS approaches, rather than a nice declarative API, but the value prop is the same). Separating the mechanics of template validation, from the available behaviors within the UI, would go a long way toward improving both features. |
I'm still wishing there was a clearer and more granular lock/allow functionality. I just created a new issue, which might be a bug (#18711), referring to the fact that what I used to do to solve most of my locking problems – lock the post type but use allowedblocks in a container block – no longer works in wordpress 5.3, at least for me. In any case it would be nice to have a better way of locking or allowing blocks and templates. Thanks for working on this. |
+1 on this, I have the exact same need. It would be awesome to have such control on the editor. |
There continue to be regular requests for additional flexibility in With the advent of controlled InnerBlocks and some of the implementation changes that are coming to InnerBlocks (thinking of #21368 in particular), I'm curious @noahtallen if you see any new options here for more structured interactions? |
I think the main thing that #21368 explores is separating things in the block-editor store which belong to separate entities (or controllers, as we refer to them within the store itself). While it doesn't directly get at the problems we have here ;), I think it is helpful in thinking about how to separate the global block list from different inner blocks which need to be different. That relates a bit more to #11681. The "block controller" stuff basically makes the code for "sync block-editor blocks with the controlling entity" the same between the top-level entity and a lower-level entity like a template part. I think we want something very similar for templateLock: we want to make template validation consistent between the global template and a local inner blocks template. Currently, template synchronization and validation runs through different code paths when it comes to top-level blocks and inner blocks. I'm not sure fixing that issue directly corresponds to creating a more flexible templateLock mechanism though :) |
I think this behavior alone makes templateLock more flexible already — and does pave the way for more sophisticated options, even if we don't support them right away! |
Just my two cents: the statement below by @chrisvanpatten in particular rings true in a few use cases for me:
I haven't mentally itemized all the use cases mentioned in this thread, but what I often bump into is use cases where we may want to control a minimum and a maximum of blocks allowed. |
This continues to be a pain point in cases where you need more intricate control over the behavior of an InnerBlocks area. There are hacks to get roughly the desired behavior, but they all come with downsides that a native API could eliminate. |
I've now lost track of the times I've had to make a block less flexible and far more restricted due to lack of a better solution here. Also allowing the conversion of items in the template - ie heading to paragraph within a semi locked down template structure is a common problem I've had to work around.
This also happens regularly when attempting workarounds - such as using dispatch to adapt the innerBlocks in the template |
Adding in another use case:
The example above is from active site with several hundred authors producing several thousand articles per week. Most of the authors have migrated from the Classic editor within the past 12 months, so there is a training component here to be dealt with internally. However, the ability to lock elements in the code editor (if not both the code and visual editors) would be incredibly useful and represent a meanginful improvement. Thanks for finding this issue and suggesting I post here, @annezazu 🙏 |
templateLock
is a property ofInnerBlocks
that allows you to "lock" an InnerBlocks area.As implemented, it is somewhat limited, with only three options: prevent all modifications, prevent inserting, and disable locking (for nested contexts).
I'd like to see a slightly more flexible approach, which reflects different needs in various nesting situations. In particular,
templateLock
doesn't currently have an option to disable inserting/removing while preserving movement, which I think could be a fairly common use-case (and what prompted me to submit this).In this more granular approach, you would pass an array of blocked actions:
Further, to better reflect that
templateLock
does not require setting atemplate
(for example if you're building your block structure programatically by dispatching insertBlocks actions), it could be renameddisabledBlockActions
(e.g.<InnerBlocks disabledBlockActions={['move', 'remove']} />
), or something similar (perhapsdisabledBlockUIActions
to be absolutely clear to developers that the locks only apply to the UI; you can still programmatically alter the block structure).I believe this flexibility would be super valuable for anyone doing more complex things with
InnerBlocks
. To me,InnerBlocks
is one of the most exciting features in Gutenberg and I think strengthening this API will have awesome benefits for developers.(Note: my use-case is most focussed on
InnerBlocks
, but I suspect these changes could be of use to custom post type templates as well!)The text was updated successfully, but these errors were encountered: