Skip to content
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

Editor: Leverage core data entities for edits, history, change detection #16761

Closed
wants to merge 6 commits into from
Closed
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
18 changes: 2 additions & 16 deletions docs/designers-developers/developers/data/data-core-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ _Related_

<a name="getBlocksForSerialization" href="#getBlocksForSerialization">#</a> **getBlocksForSerialization**

> **Deprecated** since Gutenberg 6.2.0.

Returns a set of blocks which are to be used in consideration of the post's
generated save content.

Expand Down Expand Up @@ -1041,10 +1043,6 @@ _Parameters_

- _edits_ `Object`: Post attributes to edit.

_Returns_

- `Object`: Action object.

<a name="enablePublishSidebar" href="#enablePublishSidebar">#</a> **enablePublishSidebar**

Returns an action object used in signalling that the user has enabled the
Expand Down Expand Up @@ -1143,10 +1141,6 @@ _Related_
Returns an action object used in signalling that undo history should
restore last popped state.

_Returns_

- `Object`: Action object.

<a name="refreshPost" href="#refreshPost">#</a> **refreshPost**

Action generator for handling refreshing the current post.
Expand Down Expand Up @@ -1205,10 +1199,6 @@ _Parameters_
- _blocks_ `Array`: Block Array.
- _options_ `?Object`: Optional options.

_Returns_

- `Object`: Action object

<a name="resetPost" href="#resetPost">#</a> **resetPost**

Returns an action object used in signalling that the latest version of the
Expand Down Expand Up @@ -1322,10 +1312,6 @@ Action generator for trashing the current post in the editor.

Returns an action object used in signalling that undo history should pop.

_Returns_

- `Object`: Action object.

<a name="unlockPostSaving" href="#unlockPostSaving">#</a> **unlockPostSaving**

Returns an action object used to signal that post saving is unlocked.
Expand Down
52 changes: 50 additions & 2 deletions docs/designers-developers/developers/data/data-core.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ _Returns_

- `?Array`: An array of autosaves for the post, or undefined if there is none.

<a name="getCurrentUndoOffset" href="#getCurrentUndoOffset">#</a> **getCurrentUndoOffset**

Undocumented declaration.

<a name="getCurrentUser" href="#getCurrentUser">#</a> **getCurrentUser**

Returns the current user.
Expand All @@ -83,6 +87,10 @@ _Returns_

- `Object`: Current user object.

<a name="getEditedEntityRecord" href="#getEditedEntityRecord">#</a> **getEditedEntityRecord**

Undocumented declaration.

<a name="getEmbedPreview" href="#getEmbedPreview">#</a> **getEmbedPreview**

Returns the embed preview for the given URL.
Expand Down Expand Up @@ -138,6 +146,10 @@ _Returns_

- `?Object`: Record.

<a name="getEntityRecordEdits" href="#getEntityRecordEdits">#</a> **getEntityRecordEdits**

Undocumented declaration.

<a name="getEntityRecords" href="#getEntityRecords">#</a> **getEntityRecords**

Returns the Entity's records.
Expand All @@ -153,6 +165,14 @@ _Returns_

- `Array`: Records.

<a name="getLastEntitySaveError" href="#getLastEntitySaveError">#</a> **getLastEntitySaveError**

Undocumented declaration.

<a name="getRedoEdit" href="#getRedoEdit">#</a> **getRedoEdit**

Undocumented declaration.

<a name="getThemeSupports" href="#getThemeSupports">#</a> **getThemeSupports**

Return theme supports data in the index.
Expand All @@ -165,6 +185,10 @@ _Returns_

- `*`: Index data.

<a name="getUndoEdit" href="#getUndoEdit">#</a> **getUndoEdit**

Undocumented declaration.

<a name="getUserQueryResults" href="#getUserQueryResults">#</a> **getUserQueryResults**

Returns all the users returned by a query ID.
Expand All @@ -178,6 +202,10 @@ _Returns_

- `Array`: Users list.

<a name="hasEditsForEntityRecord" href="#hasEditsForEntityRecord">#</a> **hasEditsForEntityRecord**

Undocumented declaration.

<a name="hasFetchedAutosaves" href="#hasFetchedAutosaves">#</a> **hasFetchedAutosaves**

Returns true if the REST request for autosaves has completed.
Expand All @@ -192,6 +220,14 @@ _Returns_

- `boolean`: True if the REST request was completed. False otherwise.

<a name="hasRedo" href="#hasRedo">#</a> **hasRedo**

Undocumented declaration.

<a name="hasUndo" href="#hasUndo">#</a> **hasUndo**

Undocumented declaration.

<a name="hasUploadPermissions" href="#hasUploadPermissions">#</a> **hasUploadPermissions**

> **Deprecated** since 5.0. Callers should use the more generic `canUser()` selector instead of `hasUploadPermissions()`, e.g. `canUser( 'create', 'media' )`.
Expand Down Expand Up @@ -242,6 +278,10 @@ _Returns_

- `boolean`: Whether a request is in progress for an embed preview.

<a name="isSavingEntityRecord" href="#isSavingEntityRecord">#</a> **isSavingEntityRecord**

Undocumented declaration.


<!-- END TOKEN(Autogenerated selectors) -->

Expand All @@ -261,6 +301,10 @@ _Returns_

- `Object`: Action object.

<a name="editEntityRecord" href="#editEntityRecord">#</a> **editEntityRecord**

Undocumented declaration.

<a name="receiveAutosaves" href="#receiveAutosaves">#</a> **receiveAutosaves**

Returns an action object used in signalling that the autosaves for a
Expand Down Expand Up @@ -368,6 +412,10 @@ _Returns_

- `Object`: Action object.

<a name="redo" href="#redo">#</a> **redo**

Undocumented declaration.

<a name="saveEntityRecord" href="#saveEntityRecord">#</a> **saveEntityRecord**

Action triggered to save an entity record.
Expand All @@ -378,8 +426,8 @@ _Parameters_
- _name_ `string`: Name of the received entity.
- _record_ `Object`: Record to be saved.

_Returns_
<a name="undo" href="#undo">#</a> **undo**

- `Object`: Updated record.
Undocumented declaration.

<!-- END TOKEN(Autogenerated actions) -->
41 changes: 41 additions & 0 deletions lib/compat.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,44 @@ function gutenberg_safe_style_css_column_flex_basis( $attr ) {
return $attr;
}
add_filter( 'safe_style_css', 'gutenberg_safe_style_css_column_flex_basis' );

/**
* Filters inserted post data to update an existing post's status to draft if
* currently an auto-draft. This is intended to ensure that a post which is
* explicitly updated should no longer be subjected to auto-draft purge.
*
* @param array $data An array of slashed post data.
* @param array $postarr An array of sanitized, but otherwise unmodified post
* data.
*
* @return array Filtered post data.
*/
function gutenberg_update_post_autodraft_to_draft( $data, $postarr ) {
if ( ! empty( $postarr['ID'] ) && $postarr['post_status'] === 'auto-draft' ) {
$data['post_status'] = 'draft';
}

return $data;
}
add_filter( 'wp_insert_post_data', 'gutenberg_update_post_autodraft_to_draft', 10, 2 );

/**
* Filters auto-draft post creation to unset any assigned post title. The status
* of an auto-draft should be ready from its `post_status` and not inferred via
* title. A post with an explicit title should be created as 'draft' status, not
* as 'auto-draft'.
*
* @param array $data An array of slashed post data.
* @param array $postarr An array of sanitized, but otherwise unmodified post
* data.
*
* @return array Filtered post data.
*/
function gutenberg_set_empty_auto_draft_title( $data ) {
if ( $data['post_status'] === 'auto-draft' ) {
$data['post_title'] = '';
}

return $data;
}
add_filter( 'wp_insert_post_data', 'gutenberg_set_empty_auto_draft_title' );
52 changes: 50 additions & 2 deletions packages/core-data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ _Returns_

- `Object`: Action object.

<a name="editEntityRecord" href="#editEntityRecord">#</a> **editEntityRecord**

Undocumented declaration.

<a name="receiveAutosaves" href="#receiveAutosaves">#</a> **receiveAutosaves**

Returns an action object used in signalling that the autosaves for a
Expand Down Expand Up @@ -161,6 +165,10 @@ _Returns_

- `Object`: Action object.

<a name="redo" href="#redo">#</a> **redo**

Undocumented declaration.

<a name="saveEntityRecord" href="#saveEntityRecord">#</a> **saveEntityRecord**

Action triggered to save an entity record.
Expand All @@ -171,9 +179,9 @@ _Parameters_
- _name_ `string`: Name of the received entity.
- _record_ `Object`: Record to be saved.

_Returns_
<a name="undo" href="#undo">#</a> **undo**

- `Object`: Updated record.
Undocumented declaration.

<!-- END TOKEN(Autogenerated actions) -->

Expand Down Expand Up @@ -248,6 +256,10 @@ _Returns_

- `?Array`: An array of autosaves for the post, or undefined if there is none.

<a name="getCurrentUndoOffset" href="#getCurrentUndoOffset">#</a> **getCurrentUndoOffset**

Undocumented declaration.

<a name="getCurrentUser" href="#getCurrentUser">#</a> **getCurrentUser**

Returns the current user.
Expand All @@ -260,6 +272,10 @@ _Returns_

- `Object`: Current user object.

<a name="getEditedEntityRecord" href="#getEditedEntityRecord">#</a> **getEditedEntityRecord**

Undocumented declaration.

<a name="getEmbedPreview" href="#getEmbedPreview">#</a> **getEmbedPreview**

Returns the embed preview for the given URL.
Expand Down Expand Up @@ -315,6 +331,10 @@ _Returns_

- `?Object`: Record.

<a name="getEntityRecordEdits" href="#getEntityRecordEdits">#</a> **getEntityRecordEdits**

Undocumented declaration.

<a name="getEntityRecords" href="#getEntityRecords">#</a> **getEntityRecords**

Returns the Entity's records.
Expand All @@ -330,6 +350,14 @@ _Returns_

- `Array`: Records.

<a name="getLastEntitySaveError" href="#getLastEntitySaveError">#</a> **getLastEntitySaveError**

Undocumented declaration.

<a name="getRedoEdit" href="#getRedoEdit">#</a> **getRedoEdit**

Undocumented declaration.

<a name="getThemeSupports" href="#getThemeSupports">#</a> **getThemeSupports**

Return theme supports data in the index.
Expand All @@ -342,6 +370,10 @@ _Returns_

- `*`: Index data.

<a name="getUndoEdit" href="#getUndoEdit">#</a> **getUndoEdit**

Undocumented declaration.

<a name="getUserQueryResults" href="#getUserQueryResults">#</a> **getUserQueryResults**

Returns all the users returned by a query ID.
Expand All @@ -355,6 +387,10 @@ _Returns_

- `Array`: Users list.

<a name="hasEditsForEntityRecord" href="#hasEditsForEntityRecord">#</a> **hasEditsForEntityRecord**

Undocumented declaration.

<a name="hasFetchedAutosaves" href="#hasFetchedAutosaves">#</a> **hasFetchedAutosaves**

Returns true if the REST request for autosaves has completed.
Expand All @@ -369,6 +405,14 @@ _Returns_

- `boolean`: True if the REST request was completed. False otherwise.

<a name="hasRedo" href="#hasRedo">#</a> **hasRedo**

Undocumented declaration.

<a name="hasUndo" href="#hasUndo">#</a> **hasUndo**

Undocumented declaration.

<a name="hasUploadPermissions" href="#hasUploadPermissions">#</a> **hasUploadPermissions**

> **Deprecated** since 5.0. Callers should use the more generic `canUser()` selector instead of `hasUploadPermissions()`, e.g. `canUser( 'create', 'media' )`.
Expand Down Expand Up @@ -419,6 +463,10 @@ _Returns_

- `boolean`: Whether a request is in progress for an embed preview.

<a name="isSavingEntityRecord" href="#isSavingEntityRecord">#</a> **isSavingEntityRecord**

Undocumented declaration.


<!-- END TOKEN(Autogenerated selectors) -->

Expand Down
Loading