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

PHP block registration doesn't pass all defined args #637

Closed
timotheemoulin opened this issue Apr 7, 2022 · 1 comment
Closed

PHP block registration doesn't pass all defined args #637

timotheemoulin opened this issue Apr 7, 2022 · 1 comment
Assignees

Comments

@timotheemoulin
Copy link

Hi,
When registering a new Gutenberg block in PHP all the params are not passed through the register_block_type function.

Here is a basic example.

<?php
acf_register_block(
    [
        'name'            => 'my-block',
        'title'           => 'This is my block',
        'description'     => 'Small description',
        'render_callback' => 'some_working_php_callback',
        'category'        => 'my-custom-category',
        'icon'            => 'index-card',
        'keywords'        => [ 'custom-keyword', 'list' ],
        'mode'            => 'preview',
        'supports'        => [
            'align' => false, // disable alignment selection
            'mode'  => false, // force edition in the sidebar
        ],
    ]
);

When calling WP_Block_Type_Registry::get_instance()->get_all_registered() in a script after the registration, you can see that some values are missing.

  • title
  • category
  • icon
  • description

image

All the values are correct in the Gutenberg block inserter.
image

The error seems to come from this portion of function acf_register_block_type.

<?php
// Register block type in WP.
if ( function_exists( 'register_block_type' ) ) {
    register_block_type(
        $block['name'],
        array(
            'attributes'      => acf_get_block_type_default_attributes( $block ),
            'uses_context'    => $block['usesContext'],
            'api_version'     => 2,
            'render_callback' => 'acf_render_block_callback',
        )
    );
}

When calling register_block_type() souldn't we pass all the given args?
IMO we sould try to keep consistency in the block definition between PHP and JS.

@lgladdy lgladdy self-assigned this Apr 7, 2022
@lgladdy lgladdy changed the title PHP registration doesn't passes all the args PHP block registration doesn't pass all defined args Apr 7, 2022
@lgladdy
Copy link
Member

lgladdy commented May 12, 2022

This issue will be resolved in our next release, and should be fixed now in our ACF Block Versioning Preview release available now.

@lgladdy lgladdy closed this as completed May 12, 2022
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

2 participants