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: Remove duplicate css color building functions #48700

Closed
wants to merge 1 commit into from

Conversation

scruffian
Copy link
Contributor

What?

These two functions are the same - let's move the code to a shared location.

Why?

If we're not careful we'll make changes to one and not the other and they will get out of sync.

How?

I have moved the functions to the navigation block PHP code, since these blocks require that block to work. I have also put a check that the function exists before we call it.

Testing Instructions

  1. Add overlay text and background colors to the navigation block
  2. Check that these colors appear in both the editor and the frontend, in the overlay and submenus.

@scruffian scruffian added [Block] Navigation Affects the Navigation Block [Block] Navigation Link Affects the Navigation Link Block labels Mar 2, 2023
@scruffian scruffian self-assigned this Mar 2, 2023
@github-actions
Copy link

github-actions bot commented Mar 2, 2023

Flaky tests detected in 983d9d0.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4316597094
📝 Reported issues:

* @param array $attributes Block attributes.
* @return array Colors CSS classes and inline styles.
*/
function block_core_navigation_link_build_css_colors( $context, $attributes ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since all functions in PHP are public, should we probably add _deprecated_function( __FUNCTION__, '6.2' ); to this one and just call the other function from it, right?

* @param array $attributes Block attributes.
* @return array Colors CSS classes and inline styles.
*/
function block_core_navigation_submenu_build_css_colors( $context, $attributes ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we change the name to not reference submenu here?

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
function block_core_navigation_submenu_build_css_colors( $context, $attributes ) {
function block_core_navigation_build_css_colors( $context, $attributes ) {

@@ -145,7 +74,7 @@ function render_block_core_navigation_submenu( $attributes, $content, $block ) {
return '';
}

$colors = block_core_navigation_submenu_build_css_colors( $block->context, $attributes );
$colors = function_exists( 'block_core_navigation_submenu_build_css_colors' ) ? block_core_navigation_submenu_build_css_colors( $block->context, $attributes ) : array();
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
$colors = function_exists( 'block_core_navigation_submenu_build_css_colors' ) ? block_core_navigation_submenu_build_css_colors( $block->context, $attributes ) : array();
$colors = function_exists( 'block_core_navigation_submenu_build_css_colors' ) ? block_core_navigation_build_css_colors( $block->context, $attributes ) : array();

@@ -174,7 +103,7 @@ function render_block_core_navigation_link( $attributes, $content, $block ) {
return '';
}

$colors = block_core_navigation_link_build_css_colors( $block->context, $attributes );
$colors = function_exists( 'block_core_navigation_submenu_build_css_colors' ) ? block_core_navigation_submenu_build_css_colors( $block->context, $attributes ) : array();
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
$colors = function_exists( 'block_core_navigation_submenu_build_css_colors' ) ? block_core_navigation_submenu_build_css_colors( $block->context, $attributes ) : array();
$colors = function_exists( 'block_core_navigation_build_css_colors' ) ? block_core_navigation_build_css_colors( $block->context, $attributes ) : array();

@draganescu draganescu changed the title Navigation: Remove duplicate functions Navigation: Remove duplicate css color building functions Mar 6, 2023
@draganescu
Copy link
Contributor

I would not land this PR :D - I think the duplication comes from the fact that the blocks should not have to do this work, so the "central" place is not another block but it should be something else like the style engine or some style thing. This PR is good, but it also hides the problem under the rug.

@scruffian
Copy link
Contributor Author

Closing this in favour of #48927 and #48936

@scruffian scruffian closed this Mar 8, 2023
@scruffian scruffian deleted the update/refactor-duplicate-color-function branch March 8, 2023 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Navigation Link Affects the Navigation Link Block [Block] Navigation Affects the Navigation Block
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants