| 1 |
<?php |
| 2 |
/** |
| 3 |
* Preload paths for the DataForm-based editor inspector experiment. |
| 4 |
* |
| 5 |
* @package gutenberg |
| 6 |
*/ |
| 7 |
|
| 8 |
/** |
| 9 |
* Filters the block editor preload paths. |
| 10 |
* |
| 11 |
* @param array $paths REST API paths to preload. |
| 12 |
* @param WP_Block_Editor_Context $context Block editor context. |
| 13 |
* @return array Filtered preload paths. |
| 14 |
*/ |
| 15 |
function gutenberg_dataform_inspector_preload_paths( $paths, $context ) { |
| 16 |
if ( 'core/edit-post' !== $context->name || ! isset( $context->post ) ) { |
| 17 |
return $paths; |
| 18 |
} |
| 19 |
|
| 20 |
// `DataFormPostSummary` requests the post type form config through |
| 21 |
// `useViewConfig` with `fields: [ 'form' ]`, so the preload path must |
| 22 |
// match the resulting `_fields=form` REST API request. |
| 23 |
$paths[] = '/wp/v2/view-config?kind=postType&name=' . $context->post->post_type . '&_fields=form'; |
| 24 |
|
| 25 |
return $paths; |
| 26 |
} |
| 27 |
add_filter( 'block_editor_rest_api_preload_paths', 'gutenberg_dataform_inspector_preload_paths', 10, 2 ); |
| 28 |
|