Block editors - replaces hardcoded -20 with current node ID #15063
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Prerequisites
Description
When a Block editor makes a call to
contentResource.getScaffoldByKeys()
(to get the element type schemas), it currently passed through a hardcoded ID of-20
. This patch replaces the hardcoded ID with the current page/node's ID, with a fallback on parent page/node, (and a final fallback on the previous hardcoded ID-20
.The motivation behind this pull request is that with my Contentment package's Data List editor has a feature to make use of the current page/node, but it can only do this when the
id
orparentId
parameters are available in theGetEmptyByKeys()
content API request. This works fine within page-level property-editors, but it doesn't work with the BlockList/BlockGrid editors, (this issue also applies to NestedContent, but since that is deprecated, I didn't look to patch that too).I regularly have support requests for Contentment to support Block editors better.
Steps to test
View a content page/node with either the BlockList or BlockGrid editors configured, and verify that it still works as expected.
In theory, this shouldn't be a breaking-change, but in reality, there may be a scenario where a developer is relying on the
-20
ID being present, and would break their implementation. Personally, I can't see why someone would do this, but I submit to much wiser developers than me. 馃