Skip to content
This repository was archived by the owner on Jun 19, 2025. It is now read-only.

Adds SlotFills/meta box example#153

Merged
ryanwelcher merged 3 commits intoWordPress:trunkfrom
mboynes:feature/slotfills-example
Oct 25, 2021
Merged

Adds SlotFills/meta box example#153
ryanwelcher merged 3 commits intoWordPress:trunkfrom
mboynes:feature/slotfills-example

Conversation

@mboynes
Copy link
Contributor

@mboynes mboynes commented Sep 30, 2021

This PR adds an example of using the PluginDocumentSettingPanel SlotFill to mimic a "legacy" meta box, purely in Gutenberg. This component then uses useEntityProp() to read and write post meta.

Here's a screenshot of the rendered meta box:

Screen Shot 2021-09-30 at 1 56 06 PM

TODO:

  • Add ES5 implementation

Resolves #12.

Copy link
Contributor

@ryanwelcher ryanwelcher left a comment

Choose a reason for hiding this comment

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

Thank you for putting this together! I just had one suggestion and there are some minor phpcs/linting items. I am actively working to improve the tooling here so I am not too concerned with those at the moment.

This is a great addition to the examples, thanks again!

Comment on lines +28 to +41
wp_register_script(
'gutenberg-examples-07-esnext',
plugins_url( 'build/index.js', __FILE__ ),
$asset_file['dependencies'],
$asset_file['version'],
true
);

register_block_type(
'gutenberg-examples/example-07-esnext',
[
'editor_script' => 'gutenberg-examples-07-esnext',
]
);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a little confusing to me as to why we're calling register_block_type when this feature doesn't actually register a block. I understand the use-case ( to enqueue the script ) but we can do this by calling wp_enqueue_script instead of wp_register_script above. If there are concerns about when loading the script at the correct time, I'd think that the dependencies should handle that correctly. Is there another benefit of this approach I am not aware of?

}

// automatically load dependencies and version.
$asset_file = include(plugin_dir_path(__FILE__) . 'build/index.asset.php');
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor coding standards issue

Suggested change
$asset_file = include(plugin_dir_path(__FILE__) . 'build/index.asset.php');
$asset_file = include( plugin_dir_path( __FILE__ ) . 'build/index.asset.php' );

@@ -0,0 +1,58 @@
import { TextControl } from '@wordpress/components';
Copy link
Contributor

Choose a reason for hiding this comment

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

Some minor eslint items in this file - there is a .eslintrc file in some of the earlier examples that you can copy into this directory.

@@ -0,0 +1,58 @@
import { TextControl } from '@wordpress/components';
import { useEntityProp } from '@wordpress/core-data';
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
import { useEntityProp } from '@wordpress/core-data';
/**
* WordPress dependencies
*/
import { useEntityProp } from '@wordpress/core-data';

@mboynes
Copy link
Contributor Author

mboynes commented Oct 23, 2021

Hey @ryanwelcher, thanks for the review! I believe I've addressed everything requested. My only point of confusion was the "WordPress dependencies" docblock. Your suggestion was adding it to line 2, below the TextControl import. I couldn't tell if that was a mistake or not, so I added it above that line 🤷 . Regardless, have a look and let me know if you need anything else updated!

Copy link
Contributor

@ryanwelcher ryanwelcher left a comment

Choose a reason for hiding this comment

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

Thanks for the updates! Code looks 👍 and works as expected.

@ryanwelcher ryanwelcher merged commit 0a0142e into WordPress:trunk Oct 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add examples of adding custom meta boxes to available panels

2 participants