-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Saving post in block editor always prompts for "untitled" when saving a custom entity. #68771
Comments
Hey @gschaub 👋 We discussed this ticket in a Weekly Bug Scrub in the WordPress Slack and would love to get some sample code that helps reproduce the issue. Custom Entities that aren't Post Types are quire rare & custom so getting a specific example of how you are using it would help determine the root of the issue. Thanks in advance! :) |
Hey @fabiankaegy, This is a rather large project and I wasn't certain I could just send code snippets that would be fully relevant. Therefore, I have invited you to my repository. Note that it is still in heavy development, the practical implication of which is that the code is not even close to as tidy as it will be when I get closer to publishing it. A word on what you'll find: The entity is created in edit.js. However, most of the block itself uses another store called "dynamic-tables/table". The custom entity is exclusively managed through this store which lives in the data directory. You will also see that I have tortured the code in workarounds because I cannot alter the underlying Gutenberg functionality. Finally, I am happy to share the repository with others on this team as needed. Please just supply their github user informaiton. |
@gschaub, have you tried using the See gthe lobal styles example: gutenberg/packages/core-data/src/entities.js Lines 178 to 190 in 35e99d4
|
@Mamaduka , I may be misinterpreting your question, but I know what the title of my entity is because I set it. My challenge is that I don't know how to pass a title attibute that the editor will recognize as such upon saving. Additionally, this particular method appears oriented toward the root entity 'globalStyles'. Finally, my ultimate goal is to avoid being prompted to save for my entity at all because it is simply part of the block. If I save a post with a paragraph block, the editor does not ask me if I want to save the paragraph block. It should work the same way for my block. |
@gschaub, the
This is intentional because the user is editing an entity other than the current post/page. UI allows final review before persisting changes to the DB. Example: dispatch('core').addEntities([
{
name: 'table',
kind: 'dynamic-tables',
baseURL: '/dynamic-tables/v1/tables',
baseURLParams: { context: 'edit' },
plural: 'tables',
label: __('Table'),
getTitle: ( record ) => record?.title || __( 'Table name' ),
}
]); |
Hey @Mamaduka - That worked! Thank you. I still consider this a workaround because it shouldn't be there at all. While I understand the "why" of associated with the prompt, I don't believe it considers the potential use cases for the custom entity. In this particular case, I am storing post data (i.e., associated with the block) to custom tables; it is a conscious architectural decision. I am using the entity rather that fetch because of the way entities integrate within the save/post process (i.e., it fires the the PUT, POST, DELETE method based on interaction with the Editor UI that lives outside of my block). From a user experience, having this prompt appear would be no less awkward to the user than if they were prompted for each native block (e.g., paragraph, list, quote, codes, etc.) associated with a post. My request is not to remove the prompt, but to make it optional at design time. Perhaps it could be hidden based on new entity property. Can this be linked to an enhancement request? |
Description
I am developing a custom block that includes a custom entity called "table". Upon save, the prompt shows asks if I want to save an entity record of entity type "table". The entity itself is "Untitled". I have not discovered a way to make this either avoid the prompt or provide a title for the entity record. My desire is to avoid the prompt altogether. However, if one would want a prompt, you should be able to provide a title for the entity record.
The Editor component save-publish-panes controls this prompt by selecting "hasNonPostEntityChanges" from the editor store. This essentially looks for dirty entity records where the entity's "kind" !== postType and "name" !== wp_template. In my case the custom entity has kind of "dynamic-tables/v1" (I understand from research that this must be the path to the custom plugin) and a name of "table". I have also populated the entity attribute for "title" which should be the entity record name, but it defaults back to "untitled".
Finally, the documentation for creating custom entities limited to non-existent. However, my understanding the entity must have:
This is the definition for my entity
dispatch('core').addEntities([
{
name: 'table',
kind: 'dynamic-tables',
baseURL: '/dynamic-tables/v1/tables',
baseURLParams: { context: 'edit' },
plural: 'tables',
label: __('Table')
}
]);
Step-by-step reproduction instructions
1 - Create a custom entity that is not a post type
2 - Add the custom entity to a custom block which can be edited through the block editor
3 - Create or modity a post, add the custom block to the post and save the post.
4 - The save message asks if you want to save for the custom entity with an "untitled" name
Screenshots, screen recording, code snippet
Environment info
Please confirm that you have searched existing issues in the repo.
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Please confirm which theme type you used for testing.
The text was updated successfully, but these errors were encountered: