Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backport-changelog/7.1/11272.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ https://github.com/WordPress/wordpress-develop/pull/11272
* https://github.com/WordPress/gutenberg/pull/76734
* https://github.com/WordPress/gutenberg/pull/76622
* https://github.com/WordPress/gutenberg/pull/76823
* https://github.com/WordPress/gutenberg/pull/76953
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public function get_items( $request ) {
$name = $request->get_param( 'name' );

// TODO: this data will come from a registry of view configs per entity.
$form = array();
$default_view = array(
'type' => 'table',
'filters' => array(),
Expand Down Expand Up @@ -116,6 +117,9 @@ public function get_items( $request ) {
$default_layouts = $this->get_default_layouts_for_page();
$default_view = $this->get_default_view_for_page();
$view_list = $this->get_view_list_for_page( $all_items_title, $default_layouts );
$form = $this->get_form_for_page();
} elseif ( 'postType' === $kind && 'post' === $name ) {
$form = $this->get_form_for_page();
} elseif ( 'postType' === $kind && 'wp_block' === $name ) {
$default_layouts = $this->get_default_layouts_for_wp_block();
$default_view = $this->get_default_view_for_wp_block( $default_layouts );
Expand All @@ -136,6 +140,7 @@ public function get_items( $request ) {
'default_view' => $default_view,
'default_layouts' => $default_layouts,
'view_list' => $view_list,
'form' => $form,
);

return rest_ensure_response( $response );
Expand Down Expand Up @@ -270,6 +275,12 @@ public function get_item_schema() {
),
),
),
'form' => array(
'description' => __( 'Default form configuration.', 'gutenberg' ),
'type' => 'object',
'readonly' => true,
'properties' => $this->get_form_schema(),
),
),
);

Expand Down Expand Up @@ -497,6 +508,225 @@ private function get_grid_layout_schema() {
);
}

/**
* Returns the schema for a form layout object as a discriminated union.
*
* Each variant is discriminated by a single-value enum on its `type` property,
* matching the TypeScript Layout union in dataviews/src/types/dataform.ts.
*
* @return array Schema for a form layout object.
*/
private function get_form_layout_schema() {
return array(
'oneOf' => array(
// RegularLayout.
array(
'type' => 'object',
'properties' => array(
'type' => array(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it will be important to find a way to have a single source of truth and not have to maintain the schemas both in PHP and TS.

'type' => 'string',
'enum' => array( 'regular' ),
),
'labelPosition' => array(
'type' => 'string',
'enum' => array( 'top', 'side', 'none' ),
),
),
),
// PanelLayout.
array(
'type' => 'object',
'properties' => array(
'type' => array(
'type' => 'string',
'enum' => array( 'panel' ),
),
'labelPosition' => array(
'type' => 'string',
'enum' => array( 'top', 'side', 'none' ),
),
'openAs' => array(
'oneOf' => array(
array(
'type' => 'string',
'enum' => array( 'dropdown', 'modal' ),
),
array(
'type' => 'object',
'properties' => array(
'type' => array(
'type' => 'string',
'enum' => array( 'dropdown', 'modal' ),
),
'applyLabel' => array(
'type' => 'string',
),
'cancelLabel' => array(
'type' => 'string',
),
),
),
),
),
'summary' => array(
'oneOf' => array(
array( 'type' => 'string' ),
array(
'type' => 'array',
'items' => array(
'type' => 'string',
),
),
),
),
'editVisibility' => array(
'type' => 'string',
'enum' => array( 'always', 'on-hover' ),
),
),
),
// CardLayout.
array(
'type' => 'object',
'properties' => array(
'type' => array(
'type' => 'string',
'enum' => array( 'card' ),
),
'withHeader' => array(
'type' => 'boolean',
),
'isOpened' => array(
'type' => 'boolean',
),
'isCollapsible' => array(
'type' => 'boolean',
),
'summary' => array(
'oneOf' => array(
array( 'type' => 'string' ),
array(
'type' => 'array',
'items' => array(
'oneOf' => array(
array( 'type' => 'string' ),
array(
'type' => 'object',
'properties' => array(
'id' => array(
'type' => 'string',
),
'visibility' => array(
'type' => 'string',
'enum' => array( 'always', 'when-collapsed' ),
),
),
),
),
),
),
),
),
),
),
// RowLayout.
array(
'type' => 'object',
'properties' => array(
'type' => array(
'type' => 'string',
'enum' => array( 'row' ),
),
'alignment' => array(
'type' => 'string',
'enum' => array( 'start', 'center', 'end' ),
),
'styles' => array(
'type' => 'object',
'additionalProperties' => array(
'type' => 'object',
'properties' => array(
'flex' => array(
'type' => array( 'string', 'number' ),
),
),
),
),
),
),
// DetailsLayout.
array(
'type' => 'object',
'properties' => array(
'type' => array(
'type' => 'string',
'enum' => array( 'details' ),
),
'summary' => array(
'type' => 'string',
),
),
),
),
);
}

/**
* Returns the schema for a form field item (string or object).
*
* @return array Schema for a form field.
*/
private function get_form_field_schema() {
return array(
'oneOf' => array(
array( 'type' => 'string' ),
array(
'type' => 'object',
'properties' => array(
'id' => array(
'type' => 'string',
),
'label' => array(
'type' => 'string',
),
'description' => array(
'type' => 'string',
),
'layout' => $this->get_form_layout_schema(),
'children' => array(
'type' => 'array',
'items' => array(
'oneOf' => array(
array( 'type' => 'string' ),
// This object can have the shape of a form field itself,
// allowing for recursive nesting of form fields.
// There's no easy way to codify this recursion via the JSON Schema draft-04
// supported by the REST API.
array( 'type' => 'object' ),
),
),
),
),
),
),
);
}

/**
* Returns the schema for the form configuration object.
*
* @return array Schema properties for the form configuration.
*/
private function get_form_schema() {
return array(
'layout' => $this->get_form_layout_schema(),
'fields' => array(
'type' => 'array',
'items' => $this->get_form_field_schema(),
),
);
}

private function get_default_view_for_page() {
return array(
'type' => 'list',
Expand Down Expand Up @@ -529,6 +759,65 @@ private function get_default_layouts_for_page() {
);
}

private function get_form_for_page() {
return array(
'layout' => array( 'type' => 'panel' ),
'fields' => array(
array(
'id' => 'featured_media',
'layout' => array(
'type' => 'regular',
'labelPosition' => 'none',
),
),
array(
'id' => 'post-content-info',
'layout' => array(
'type' => 'regular',
'labelPosition' => 'none',
),
),
'excerpt',
array(
'id' => 'status',
'label' => __( 'Status', 'gutenberg' ),
'children' => array(
array(
'id' => 'status',
'layout' => array(
'type' => 'regular',
'labelPosition' => 'none',
),
),
'scheduled_date',
'password',
'sticky',
),
),
'date',
'slug',
'author',
'template',
array(
'id' => 'discussion',
'label' => __( 'Discussion', 'gutenberg' ),
'children' => array(
array(
'id' => 'comment_status',
'layout' => array(
'type' => 'regular',
'labelPosition' => 'none',
),
),
'ping_status',
),
),
'parent',
'format',
),
);
}

private function get_view_list_for_page( $all_items_title, $default_layouts ) {
return array(
array(
Expand Down
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/core-data/src/private-selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ export function getViewConfig(
default_view: undefined,
default_layouts: undefined,
view_list: undefined,
form: undefined,
}
);
}
2 changes: 2 additions & 0 deletions packages/edit-site/src/components/post-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export default function PostList( { postType } ) {
default_view: defaultView,
default_layouts: defaultLayouts,
view_list: viewList,
form: quickEditForm,
} = useViewConfig( {
kind: 'postType',
name: postType,
Expand Down Expand Up @@ -339,6 +340,7 @@ export default function PostList( { postType } ) {
postType={ postType }
postId={ selection }
closeModal={ closeQuickEditModal }
quickEditForm={ quickEditForm }
/>
) }
</Page>
Expand Down
Loading
Loading