Closed
Conversation
|
Size Change: +718 B (0%) Total Size: 1.35 MB
ℹ️ View Unchanged
|
|
Flaky tests detected in a78e12c. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4608099658
|
Member
Author
|
We will only be using this for footnotes for now. #47682 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What?
This is a first attempt at storing data in rich text with dynamic replacement both in rich text and server side. For this, we will use the
<data>HTML tag since it fits semantically and doesn't have any default styling. The full syntax will be:We will use the dataset as attributes and the HTML content can be used as the implementor sees fit.
Use case: current year
In templates, it's useful to display the current year in the footer for example. This can now be done with the
core/current-yearformat type. On insertion, a data tag will be injected into rich text:The format type's
renderfunction will be called to render the contents. When serialising the HTML, the format type'ssaveFallbackfunction will be called. In this case it's both the same:So the content that will be stored in the post is:
If for some reason the PHP display filters don't run, the year will render fine, though of course not the current year. In this case a fallback is perhaps not needed because this dynamic content will most likely only be used in templates, but it might be useful for other types of content.
Now on the PHP side, there's a helper function
replaceDataByType.Use case: post meta, e.g. date
We can handle the post date similarly, but the case is a bit more interesting because it allows attributes.
On top of that, we need post meta data. This will be the render function:
In this case, if we don't provide a fallback function, only the data tag will be saved without any content (
<data value="core/current-year" data-display-type="modified" data-format="F j, Y g:i a"></data>).And now again in PHP:
But here is the interesting thing: if I create a pattern, I can use the content of the data tag as a placeholder. This means that if my pattern is viewed somewhere outside of context, you'll be able to see the placeholder. When you copy the pattern over to your site, that placeholder will disappear and be replaced.
Use case: footnotes
We can use this API for footnotes too. More on that here: https://github.com/WordPress/gutenberg/pull/47682/files
Why?
How?
Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast