PluginProbe
Gutenberg / 24.0.0
Gutenberg v24.0.0
24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 All 403 releases
gutenberg / lib / compat / wordpress-7.2 / view-config-api.php

view-config-api.php in Gutenberg 24.0.0, at lib/compat/wordpress-7.2/view-config-api.php

267 lines 7.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Entity view configuration additions, layered on top of the base
4 * configurations in `lib/compat/wordpress-7.1/view-config-api.php`.
5 *
6 * @package gutenberg
7 */
8
9 /**
10 * Adds the `reading_settings` field to the `wp_template` form configuration.
11 *
12 * The `fields` list is pinned rather than merged because a merged member is
13 * appended to the end of the list, and the link belongs above the last edited
14 * date. Keep it in sync with the list built in
15 * _gutenberg_get_entity_view_config_posttype_wp_template().
16 *
17 * @param Gutenberg_View_Config_Data $data The view configuration container for the entity.
18 * @return Gutenberg_View_Config_Data The updated view configuration container.
19 */
20 function _gutenberg_add_reading_settings_to_wp_template_view_config( $data ) {
21 return $data->replace(
22 array(
23 'form' => array(
24 'fields' => array(
25 array(
26 'id' => 'description',
27 'layout' => array(
28 'type' => 'panel',
29 'labelPosition' => 'top',
30 ),
31 ),
32 array(
33 'id' => 'description_readonly',
34 'layout' => array(
35 'type' => 'regular',
36 'labelPosition' => 'none',
37 ),
38 ),
39 array(
40 'id' => 'reading_settings',
41 'layout' => array(
42 'type' => 'regular',
43 'labelPosition' => 'none',
44 ),
45 ),
46 array(
47 'id' => 'last_edited_date',
48 'layout' => array(
49 'type' => 'panel',
50 'labelPosition' => 'none',
51 ),
52 ),
53 'revisions',
54 // The following fields are only meaningful in the `home`/`index`
55 // template summary. They edit other entities (`root/site` and the
56 // posts page); the editor merges those records into the form data
57 // under a namespace and controls when the fields are shown.
58 'posts_page_title',
59 'posts_per_page',
60 'default_comment_status',
61 ),
62 ),
63 ),
64 1
65 );
66 }
67
68 /**
69 * Removes the `active`, `slug`, and `theme` fields from the `wp_template`
70 * default view.
71 *
72 * They were rendered by the template activation experiment, which has been
73 * removed. No field with those ids is registered for templates anymore.
74 *
75 * @param Gutenberg_View_Config_Data $data The view configuration container for the entity.
76 * @return Gutenberg_View_Config_Data The updated view configuration container.
77 */
78 function _gutenberg_remove_stale_fields_from_wp_template_view_config( $data ) {
79 return $data->remove(
80 array(
81 'default_view' => array(
82 'fields' => array( 'active', 'slug', 'theme' ),
83 ),
84 ),
85 1
86 );
87 }
88
89 /**
90 * Provides the view configuration for the `wp_navigation` post type.
91 *
92 * Core has no callback for this post type, so this is a base definition
93 * rather than a layer on top of one.
94 *
95 * @param Gutenberg_View_Config_Data $data The view configuration container for the entity.
96 * @return Gutenberg_View_Config_Data The updated view configuration container.
97 */
98 function _gutenberg_get_entity_view_config_posttype_wp_navigation( $data ) {
99 $default_layouts = array(
100 'list' => array(),
101 );
102
103 $default_view = array(
104 'type' => 'list',
105 'filters' => array(),
106 'perPage' => 20,
107 'sort' => array(
108 'field' => 'date',
109 'direction' => 'desc',
110 ),
111 'titleField' => 'title',
112 'fields' => array(),
113 );
114
115 // The base config already provides the "All" view titled with the post
116 // type's `all_items` label, so only the default view and layouts change.
117 $data->set(
118 array(
119 'default_view' => $default_view,
120 'default_layouts' => $default_layouts,
121 ),
122 1
123 );
124
125 return $data;
126 }
127
128 /**
129 * Provides the view configuration for the `root`/`site` entity.
130 *
131 * The site settings are a singleton record edited through a form (the site
132 * editor's Identity screen) rather than listed in a view, so only the `form`
133 * is defined here. The generic `default_view`, `default_layouts`, and
134 * `view_list` built by gutenberg_get_entity_view_config() are left untouched.
135 *
136 * Core has no callback for this entity, so this is a base definition rather
137 * than a layer on top of one.
138 *
139 * @param Gutenberg_View_Config_Data $data The view configuration container for the entity.
140 * @return Gutenberg_View_Config_Data The updated view configuration container.
141 */
142 function _gutenberg_get_entity_view_config_root_site( $data ) {
143 return $data->set(
144 array(
145 'form' => array(
146 'layout' => array(
147 'type' => 'regular',
148 'labelPosition' => 'top',
149 ),
150 'fields' => array(
151 'title',
152 'description',
153 'site_logo',
154 'site_icon',
155 ),
156 ),
157 ),
158 1
159 );
160 }
161
162 /**
163 * Post types whose base definition provides its own `form`, without the
164 * `status` and `discussion` groups of the default post type form.
165 *
166 * @var string[]
167 */
168 const GUTENBERG_VIEW_CONFIG_POST_TYPES_WITH_OWN_FORM = array( 'wp_block', 'wp_template', 'wp_template_part' );
169
170 /**
171 * Makes the panel summary of the `status` and `discussion` groups explicit in
172 * the default post type form.
173 *
174 * Both groups used to be summarized by the field sharing their id (`status`,
175 * and the composite `discussion` field). A combined form field no longer
176 * resolves its own id against the field definitions, so the summary field is
177 * declared through `layout.summary` instead. The patch merges into the existing
178 * group members by id, leaving the rest of the form untouched.
179 *
180 * @param Gutenberg_View_Config_Data $data The view configuration container for the entity.
181 * @return Gutenberg_View_Config_Data The updated view configuration container.
182 */
183 function _gutenberg_add_group_summaries_to_default_posttype_form( $data ) {
184 return $data->merge(
185 array(
186 'form' => array(
187 'fields' => array(
188 array(
189 'id' => 'status',
190 'layout' => array(
191 'type' => 'panel',
192 'summary' => 'status',
193 ),
194 ),
195 array(
196 'id' => 'discussion',
197 'layout' => array(
198 'type' => 'panel',
199 'summary' => 'discussion',
200 ),
201 ),
202 ),
203 ),
204 ),
205 1
206 );
207 }
208
209 /**
210 * Layers the group summaries on top of the view configuration of every post
211 * type that uses the default form, including custom post types registered at
212 * any point.
213 *
214 * The callback merges by member id, and a member that is absent would be
215 * appended instead, so post types whose base definition provides its own form
216 * are skipped.
217 *
218 * @param string $post_type The post type being registered.
219 */
220 function gutenberg_register_default_posttype_form_summaries_7_2( $post_type ) {
221 if ( in_array( $post_type, GUTENBERG_VIEW_CONFIG_POST_TYPES_WITH_OWN_FORM, true ) ) {
222 return;
223 }
224
225 add_filter(
226 gutenberg_get_entity_view_config_hook_name( 'postType', $post_type ),
227 '_gutenberg_add_group_summaries_to_default_posttype_form',
228 6,
229 1
230 );
231 }
232 add_action( 'registered_post_type', 'gutenberg_register_default_posttype_form_summaries_7_2' );
233
234 /**
235 * Registers the entity view configuration filters that layer on top of the base
236 * definitions, at a priority between those (5) and third-party callbacks (10),
237 * and the base definitions for entities that gained one in 7.2, at the base
238 * priority (5).
239 */
240 function gutenberg_register_entity_view_config_filters_7_2() {
241 add_filter(
242 gutenberg_get_entity_view_config_hook_name( 'postType', 'wp_navigation' ),
243 '_gutenberg_get_entity_view_config_posttype_wp_navigation',
244 5,
245 1
246 );
247 add_filter(
248 gutenberg_get_entity_view_config_hook_name( 'root', 'site' ),
249 '_gutenberg_get_entity_view_config_root_site',
250 5,
251 1
252 );
253 add_filter(
254 gutenberg_get_entity_view_config_hook_name( 'postType', 'wp_template' ),
255 '_gutenberg_add_reading_settings_to_wp_template_view_config',
256 6,
257 1
258 );
259 add_filter(
260 gutenberg_get_entity_view_config_hook_name( 'postType', 'wp_template' ),
261 '_gutenberg_remove_stale_fields_from_wp_template_view_config',
262 6,
263 1
264 );
265 }
266 add_action( 'init', 'gutenberg_register_entity_view_config_filters_7_2' );
267