Repository navigation
Try: Add "reading settings" link to Front Page template #81987
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
9931437
Try: Add "reading settings" link to Front Page template.
jasmussen d5fa92b
Simplify.
jasmussen 7d077e0
Merge branch 'trunk' into add/reading-settings-link
t-hamano 371378d
Move the reading_settings view config field to the WordPress 7.2 comp…
t-hamano ea06537
Extract ReadingSettingsLink so both post summaries share one self-gat…
t-hamano a43979a
Simplify the view config PHPDoc and drop comments that restate the code
t-hamano 3cac377
Restore the PostViewLink comment removed unintentionally
t-hamano 9515695
small ReadingSettingsLink refactor
ntsekouras 4355288
Add backport changelog entry for Core PR 13266
t-hamano e34dbff
Docs: Document view config filter priority and merge ordering constra…
t-hamano 8e3923d
Merge branch 'trunk' into add/reading-settings-link
t-hamano 7617eec
Rename ReadingSettingsLink to .tsx so its JSX is type checked
t-hamano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| https://github.com/WordPress/wordpress-develop/pull/13266 | ||
|
|
||
| * https://github.com/WordPress/gutenberg/pull/81987 |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| <?php | ||
| /** | ||
| * Entity view configuration additions, layered on top of the base | ||
| * configurations in `lib/compat/wordpress-7.1/view-config-api.php`. | ||
| * | ||
| * @package gutenberg | ||
| */ | ||
|
|
||
| /** | ||
| * Adds the `reading_settings` field to the `wp_template` form configuration. | ||
| * | ||
| * The `fields` list is pinned rather than merged because a merged member is | ||
| * appended to the end of the list, and the link belongs above the last edited | ||
| * date. Keep it in sync with the list built in | ||
| * _gutenberg_get_entity_view_config_posttype_wp_template(). | ||
| * | ||
| * @param Gutenberg_View_Config_Data $data The view configuration container for the entity. | ||
| * @return Gutenberg_View_Config_Data The updated view configuration container. | ||
| */ | ||
| function _gutenberg_add_reading_settings_to_wp_template_view_config( $data ) { | ||
| return $data->replace( | ||
| array( | ||
| 'form' => array( | ||
| 'fields' => array( | ||
| array( | ||
| 'id' => 'description', | ||
| 'layout' => array( | ||
| 'type' => 'panel', | ||
| 'labelPosition' => 'top', | ||
| ), | ||
| ), | ||
| array( | ||
| 'id' => 'description_readonly', | ||
| 'layout' => array( | ||
| 'type' => 'regular', | ||
| 'labelPosition' => 'none', | ||
| ), | ||
| ), | ||
| array( | ||
| 'id' => 'reading_settings', | ||
| 'layout' => array( | ||
| 'type' => 'regular', | ||
| 'labelPosition' => 'none', | ||
| ), | ||
| ), | ||
| array( | ||
| 'id' => 'last_edited_date', | ||
| 'layout' => array( | ||
| 'type' => 'panel', | ||
| 'labelPosition' => 'none', | ||
| ), | ||
| ), | ||
| 'revisions', | ||
| // The following fields are only meaningful in the `home`/`index` | ||
| // template summary. They edit other entities (`root/site` and the | ||
| // posts page); the editor merges those records into the form data | ||
| // under a namespace and controls when the fields are shown. | ||
| 'posts_page_title', | ||
| 'posts_per_page', | ||
| 'default_comment_status', | ||
| ), | ||
| ), | ||
| ), | ||
| 1 | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Registers the entity view configuration filters that layer on top of the base | ||
| * definitions, at a priority between those (5) and third-party callbacks (10). | ||
| */ | ||
| function gutenberg_register_entity_view_config_filters_7_2() { | ||
| add_filter( | ||
| gutenberg_get_entity_view_config_hook_name( 'postType', 'wp_template' ), | ||
| '_gutenberg_add_reading_settings_to_wp_template_view_config', | ||
| 6, | ||
| 1 | ||
| ); | ||
| } | ||
| add_action( 'init', 'gutenberg_register_entity_view_config_filters_7_2' ); | ||
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
36 changes: 36 additions & 0 deletions
36
packages/editor/src/components/reading-settings-link/index.tsx
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import { __ } from '@wordpress/i18n'; | ||
| import { useSelect } from '@wordpress/data'; | ||
| import { store as coreStore } from '@wordpress/core-data'; | ||
| import { Link } from '@wordpress/ui'; | ||
| import { store as editorStore } from '../../store'; | ||
| import { TEMPLATE_POST_TYPE } from '../../store/constants'; | ||
|
|
||
| /** | ||
| * Links to the Reading settings screen from the Front Page template summary. | ||
| * That template resolves to the site homepage whether the homepage shows the | ||
| * latest posts or a static page, so it points at where that choice is made. | ||
| * | ||
| * @return The rendered component. | ||
| */ | ||
| export default function ReadingSettingsLink() { | ||
| const isVisible = useSelect( ( select ) => { | ||
| const { getCurrentPostType, getEditedPostAttribute } = | ||
| select( editorStore ); | ||
| const { canUser } = select( coreStore ); | ||
| return ( | ||
| getCurrentPostType() === TEMPLATE_POST_TYPE && | ||
| getEditedPostAttribute( 'slug' ) === 'front-page' && | ||
| !! canUser( 'update', { kind: 'root', name: 'site' } ) | ||
| ); | ||
| }, [] ); | ||
|
|
||
| if ( ! isVisible ) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <div> | ||
| <Link href="options-reading.php">{ __( 'Reading settings' ) }</Link> | ||
| </div> | ||
| ); | ||
| } |
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
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
16 changes: 16 additions & 0 deletions
16
packages/editor/src/dataviews/fields/reading-settings/index.tsx
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import type { Field } from '@wordpress/dataviews'; | ||
| import type { BasePost } from '@wordpress/fields'; | ||
| import { __ } from '@wordpress/i18n'; | ||
| import ReadingSettingsLink from '../../../components/reading-settings-link'; | ||
|
|
||
| const readingSettingsField: Field< BasePost > = { | ||
| id: 'reading_settings', | ||
| type: 'text', | ||
| label: __( 'Reading settings' ), | ||
| readOnly: true, | ||
| enableSorting: false, | ||
| render: ReadingSettingsLink, | ||
| isVisible: ( item ) => item.slug === 'front-page', | ||
| }; | ||
|
|
||
| export default readingSettingsField; |
Oops, something went wrong.
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.
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.
I think changes are fine here and
replaceat that priority is what makes such core changes possible.It's worth updating the docs to mention that consumers should not use a priority lower of
10(reserved by core).3rd party consumers right now can only append new fields when merging and that was intentional for now, due to the challenges to properly support ordering in a filter.
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.
Do you think the content added in e34dbff is sufficient?