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

Support for block color and background parameters #54

Open
infobahn opened this issue Nov 3, 2021 · 3 comments
Open

Support for block color and background parameters #54

infobahn opened this issue Nov 3, 2021 · 3 comments
Assignees

Comments

@infobahn
Copy link

infobahn commented Nov 3, 2021

Currently there are no parameters to enable support for color or background color on blocks. Could these be added?

I wondered if I could enable this via a filter, but it doesn't seem to work the way I was trying to achieve it:

add_filter( 'timber/acf-gutenberg-blocks-default-data', function( $data ){
    $data['default'] = array(
        'supports'          => array(
            'color'             => array (
                'color'             => true,
                'background'        => true
            ),
        ),
    );
    return $data;
} );
@palmiak
Copy link
Owner

palmiak commented Nov 5, 2021

I will try to check this out next week.

Although not all parameters work with ACF. If they are compatible, I'll add them,

@palmiak palmiak self-assigned this Nov 5, 2021
@infobahn
Copy link
Author

infobahn commented Nov 5, 2021

Very much appreciated, thanks. The color and background parameters do work with the standard ACF method of registering blocks, so fingers crossed it should be possible.

@Mytraas
Copy link

Mytraas commented Nov 3, 2023

Old here but if you need a fix, you can change the method timber_block_default_data.

Line 386, replace array_merge by array_merge_recursive.

Then in function.php ( or anywhere you want ), write this code:

add_filter( 'timber/acf-gutenberg-blocks-default-data', function( $data ){
    $data['default'] = array(
        'supports'          => array(
            'color'             => array (
                'text'             => true,
                'background'        => true
            ),
			"typography" => array(
				"fontSize" => true
			),
        ),
    );
    return $data;
} );

add_filter( 'timber/acf-gutenberg-blocks-data', function( $context ){

	$classes = array_merge(
		array( 'has-' . $context['block']['fontSize'] . '-font-size' ),
		array( 'has-text-color has-' . $context['block']['textColor'] . '-color' ),
		array( 'has-background has-' . $context['block']['backgroundColor'] . '-background-color' )
	);
	
	$context['block']['className'] = $context['block']['className'] . ' ' . implode( ' ', $classes );
    return $context;
} );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants