-
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
ACF & Gutenberg Help List #12692
Comments
Hi Thanks for opening the issue.
The main way to listen to data changes or update data in Gutenberg is to use the data module ( In order to subscribe to changes you use Here are some links that could be helpful here:
These questions are all related and have the same answers. So you probably can't continue to use CSS to target these elements. Even if you probably can do it for some of them, I would consider a hack as the DOM is not an official API and if the element in question is rendered with React (most of them), it can get rerendered which overrides any DOM change you can make imperatively. That said, we have a list of "selectors" and "actions" to show/hide these elements using the data module:
We do provide data module actions whether a post is not savable at any given moment, which will allow disable the publish buttons in consequence.
Same reply to the initial question, you can retrieve all this informations from the data module. https://github.com/WordPress/gutenberg/blob/master/packages/editor/src/store/effects/posts.js#L61-L85 This snippet should give you an idea of what Gutenberg does to retrieve the Data sent to the save API request. you can use the exact same selectors to retrieve this data.
There's an API to display notice messages (similar to the notices Gutenberg itself displays when you save a post...) You can checkout the list of selectors and actions available here
This has been discussed and the decision was to not support this hook/filter at the moment mainly because the goal of Gutenberg is to allow visual editing which means in phase2 and beyond we may be able to edit the whole page/site using the Gutenberg editor. This means for instance the post title becomes a block, the post content becomes a block with inner blocks... you'd be able to reorder those, add sidebar elements.... This means that allowing the
Having a MetaBox on the editor will automatically trigger a second save request for backwards compatibility reasons, there's no way for Gutenberg "to know" what the meta-box is doing and most metabox rely on the To avoid having to trigger another save function, I'd suggest avoiding the meta box API entirely and will suggest using the Plugin API. Several parts of the Gutenberg UI offer what we call "Slots". For example you can register a Sidebar Slot, to have a sidebar dedicated to your own plugin, a modal, ... Read more here: I hope this helps. |
@chrisvanpatten - can we make sure that the most important points from @youknowriad's answers are included in our docs? I think we have many of those areas covered already, but some of them need to be updated with more details. We might also want to add a section which general guidelines on how to build plugins. |
Thinking out loud, one could use a similar method as the metaboxes to render the after title section in PHP, then use a react portal to hoist it inside a block created by ACF JS and inserted at the beginning of the relevant post types, then strip out that block. Keeping in mind that blocks can choose to store their data in post meta rather than post content |
Issue 3 is big blocker for myself as well in integrating with Gutenberg with just meta boxes (and probably blocks too...). Currently, the integration with meta boxes works fine for my plugin info is saved and validation passes/fails but there's no feedback. If the minimum required info is not valid, then we revert the post to draft during the save process and put out an admin notice. There doesn't seem to be a clean way to do this... I would have hoped that this would still be done fully server-side so the result of the save attempt is modified before sent back to the editor. |
Hi @elliotcondon! Looking forward to spending some time helping out with ACF! I'll start by answering as many of your questions here as I can. I'll then move over into the ACF repo and hopefully help out there with some contributions. Feel free to hit me up at any time either here or on the Making WordPress Slack. Could you let me know the current status of the issues that you've outlined in your original comment here? Are they all outstanding, or have some been addressed in ACF? |
I've done my best to elaborate on all the questions above. I've used 📌 to mark likely action items for me on the Gutenberg side of things. Hope it helps! Issue 1: Dynamic metaboxes
If we have a React component then we can make it update when there are changes by wrapping it with let pageTemplate;
wp.data.subscribe( () => {
const newPageTemplate = wp.data.select( 'core/editor' ).getEditedPostAttribute( 'template' );
if ( pageTemplate !== newPageTemplate ) {
console.log( 'Page template has changed!' );
pageTemplate = newPageTemplate;
}
} );
const { getEditedPostAttribute } = wp.data.select( 'core/editor' );
const pageTemplate = getEditedPostAttribute( 'template' );
const pageParent = getEditedPostAttribute( 'parent' );
const postFormat = getEditedPostAttribute( 'format' );
const postTerms = getEditedPostAttribute( 'taxonomy_name' ); // e.g. 'tags', 'categories'
Dispatching // Hides the 'postcustom' meta box
wp.data.dispatch( 'core/edit-post' ).removeEditorPanel( 'meta-box-postcustom' );
By this do you mean the checkboxes that appear in the Options modal? If so, then those can be toggled by using // Toggles the 'my-box' meta box
wp.data.dispatch( 'core/edit-post' ).toggleEditorPanelEnabled( 'meta-box-my-box' ); Issue 2: Hide on Screen settings
Some panels can be removed by dispatching wp.data.dispatch( 'core/edit-post' ).removeEditorPanel( 'post-link' ); // Permalink
wp.data.dispatch( 'core/edit-post' ).removeEditorPanel( 'post-excerpt' ); // Excerpt
wp.data.dispatch( 'core/edit-post' ).removeEditorPanel( 'discussion-panel' ); // Discussion
wp.data.dispatch( 'core/edit-post' ).removeEditorPanel( 'page-attributes' ); // Page Attributes
wp.data.dispatch( 'core/edit-post' ).removeEditorPanel( 'featured-image' ); // Featured Image
wp.data.dispatch( 'core/edit-post' ).removeEditorPanel( 'post-status' ); // Status & Visibility 📌 We'll need to expand this API so that the rest of your use cases are covered: Comments, Revisions, Slug, Author, Format, Categories, Tags, Send Trackbacks. We also will need to improve the documentation here. Not sure what you mean by disabling Content Editor. Is that a panel?
Using CSS will do the job here but it's not an official API that we support. That is, we might change a CSS selector in the future without any warning.
📌 For this we will likely will need to change the Issue 3: AJAX Validation
Post saving can be disabled and enabled by dispatching // Prevent the post from being saved
wp.data.dispatch( 'core/editor' ).lockPostSaving( 'acf' );
// Allow the post to be saved
wp.data.dispatch( 'core/editor' ).unlockPostSaving( 'acf' ); One approach to get this ACF feature working with Gutenberg might be to:
const { getEditedPostAttribute } = wp.data.select( 'core/editor' );
const title = getEditedPostAttribute( 'title' );
const content = getEditedPostAttribute( 'content' );
I don't think this is practical because of how meta boxes are implemented in Gutenberg. I suggest looking into an approach like the one outlined above.
Yes, the Notices API is what we'll want here. Namely, wp.data.dispatch( 'core/notices' ).createErrorNotice( 'Something is not good!' ); Issue 4: Position “high”
As Riad mentioned above, the Right now we only support Issue 5: Metabox Styling & Issue 6: Metabox Saving
Yes, such a discussion is probably best left to a follow-up issue that has a Design label.
We're running into some of the limitations of the metabox API here. Gutenberg only implements support for metaboxes with a view towards maintaining backwards compatibility. It's expected that in the medium to long term, plugins will move towards other APIs (e.g. Slot/Fill, Plugins) to implement their functionality. For example, ACF could implement React components that render the UI for editing Custom Fields. These components could use the WordPress component library to achieve a native look and feel. This UI could then be slotted into parts of the Gutenberg editor e.g. the sidebar using our Plugins API. Would it be helpful if I put together an example on how ACF could use our APIs to render a Gutenberg-native UI in the sidebar for editing ACF Custom Fields? |
@noisysocks This may be a little off topic but I just had to comment. After over a week of stumbling around in the dark trying to figure out how to add an admin notice because the documentation on pretty much everything is woefully lacking, in a single comment you managed to shed some much needed light on interacting with this component and several other things. It's amazing what a few lines of simple code and some simple explanations can do for us idiots that are not already entrenched in the GB code. |
Glad I could help you out @Hube2. Agree that documentation is something we need to work on. |
@noisysocks Thanks for your help with the above questions. I've gone ahead and created a unique GitHub issue for each of the major items. This should make it a bit easier to follow the conversations. Please find links to these GitHub issues in the "edited" original topic above. |
@youknowriad @noisysocks Thanks a lot for your explanation. We are having similar issues with Gutenberg for our Meta Box plugin. 2 biggest issues are conditional logic (e.g. dynamic meta boxes as described here) and validation. The conditional logic part seems to be doable with the Validation is kind of more complicated thing. We're using HTML5 validation (such as |
@rilwis: I'm assuming that you want to disable post saving and publishing when there is a validation error? One approach might be to add an event listener that runs when there is a validation error. When this happens, call |
Thanks @elliotcondon, good idea. Let's continue discussion over in the linked issues. |
@noisysocks Thanks. That would work for JS validation. HTML5 validation seems to be not supported in issue #5883. |
+1, following... |
@noisysocks Thanks. You saved me hours of search. However, I am still not able to remove the editor panel for |
Hi all 👋.
Thanks in advance for any help, links and code examples you are able to provide.
Overview
The purpose of this GitHub issue is to establish a list of the current issues that exist between ACF & Gutenberg so that we may ask those reading to contribute constructive solutions, code examples, links, ideas and help. This is not a discussion board for thoughts or opinions, nor is it an attempt to provoke such comments.
If you are able to share knowledge, thank you, and please remember to provide references when possible. Please let me know if you would like this ticket moved to the ACF GitHub repo instead.
✏️ Update: Compatibility issues have been split into individual GitHub issues for streamlined comments and ease of maintenance.
Compatibility issues
💚 Dynamic metaboxes
Status: Fixed in 5.7.9 but requires further improvement.
Link: AdvancedCustomFields/acf#111
💛 Hide on Screen settings
Status: Broken. Researching solutions.
Link: AdvancedCustomFields/acf#112
💛 PHP/AJAX Validation
Status: Broken. Researching solutions.
Link: AdvancedCustomFields/acf#113
💚 Custom metabox location
Status: Fixed in 5.7.9 but requires further improvement.
AdvancedCustomFields/acf#114
Thanks
Thanks for getting this far and again for providing any help on the above issue.
ACF
The text was updated successfully, but these errors were encountered: