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

Navigation: Allow additional CSS classes #18466

Merged
merged 6 commits into from
Nov 15, 2019
Merged
Changes from 5 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
20 changes: 7 additions & 13 deletions packages/block-library/src/navigation-menu/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,14 @@ function build_css_colors( $attributes ) {
* @return string Returns the post content with the legacy widget added.
*/
function render_block_navigation_menu( $attributes, $content, $block ) {
$colors = build_css_colors( $attributes );
$class_attribute = sprintf( ' class="%s"', esc_attr( $colors['css_classes'] ? 'wp-block-navigation-menu ' . $colors['css_classes'] : 'wp-block-navigation-menu' ) );
$style_attribute = $colors['inline_styles'] ? sprintf( ' style="%s"', esc_attr( $colors['inline_styles'] ) ) : '';
$colors = build_css_colors( $attributes );
obenland marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

Is this function build_css_colors not intended to be namespaced / prefixed specific to the plugin / block / WordPress? (i.e. is it meant to be for general usage?)

Copy link
Member Author

Choose a reason for hiding this comment

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

Is there a namespacing standard for PHP functions in Gutenberg?

Copy link
Member

Choose a reason for hiding this comment

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

Is there a namespacing standard for PHP functions in Gutenberg?

Now that you mention it, not explicitly.

For most functions, we follow best practices in using a gutenberg_ prefix for plugin-specific functions.

It's a little trickier for these blocks though, since they're copied verbatim into core. So the concern is in considering that, should this be merged to core, these become new global WordPress functions.

Most other dynamic blocks follow some convention of render_block_foo and register_block_foo, but there's definitely some (unfortunate) ad hoc naming for similar utility functions (example).

It's definitely not a blocker for merging this pull request, since it wasn't introduced here, but we should see about establishing a convention here that makes sense.

Copy link
Member Author

@obenland obenland Nov 15, 2019

Choose a reason for hiding this comment

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

namespace Gutenberg; 😱

$classes = array( 'wp-block-navigation-menu', $attributes['className'], $colors['css_classes'] );
$classes = join( ' ', array_filter( $classes ) );

return sprintf(
implode(
"\n",
array(
'<nav%s%s>',
' %s',
'</nav>',
)
),
$class_attribute,
$style_attribute,
'<nav class="%1$s" %2$s>%3$s</nav>',
esc_attr( $classes ),
$colors['inline_styles'] ? sprintf( 'style="%s"', esc_attr( $colors['inline_styles'] ) ) : '',
build_navigation_menu_html( $block, $colors )
);
}
Expand Down