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

Adding ACF Blocks causes error and blocks return null #34

Open
julienkos opened this issue Mar 19, 2022 · 7 comments
Open

Adding ACF Blocks causes error and blocks return null #34

julienkos opened this issue Mar 19, 2022 · 7 comments

Comments

@julienkos
Copy link

Hi there, if you create a custom acf block (gutenberg), no data comes back. I received the following message:

{ "errors": [ { "debugMessage": "get_object_vars(): Argument #1 ($object) must be of type object, array given", "message": "Internal server error", "extensions": { "category": "internal" }, "locations": [ { "line": 5, "column": 7 } ], "path": [ "pages", "nodes", 0, "blocks" ] } ], "data": { "pages": { "nodes": [ { "title": "Home", "blocks": null } ] } }, "extensions": { "debug": [] } }

Any advice on how to fix this issue?

As for steps to reproduce:

  1. Added function to functions.php to register block.
  2. Added fields to block through ACF.
  3. Added block to home page.
  4. Tried to make graphql call.
  5. Error is shown.

I am using the latest version of ACF Pro.

@drewbaker
Copy link
Member

That’s weird. We use custom blocks a lot.

Whats your GQL look like?

@drewbaker
Copy link
Member

Can you also post your PHP for the block registration?

@julienkos
Copy link
Author

Hi Drew, thank you for the quick reply!

Here is the PHP

acf_register_block_type(array( 'name' => 'hero', 'title' => __('Hero'), 'description' => __('A custom hero block.'), 'render_template' => get_template_directory() . '/template-parts/blocks/hero/hero.php', ));

Turns out this alone doesn't cause the issue. It only starts when I add a field to the block.

I set "Show in GraphQL" to yes and everything else is default. I can make a video to show if you like.

@drewbaker
Copy link
Member

This is what I have on a site that is working great:

<?php 
/*
 * Register custom ACF blocks
 * SEE https://www.advancedcustomfields.com/resources/blocks/
 * SEE https://www.advancedcustomfields.com/resources/acf_register_block_type/
 */
 
function fuxt_custom_blocks() {

    // Abort early if custom blocks not supported (not ACF Pro).
    if( !function_exists('acf_register_block_type') ) {
		return;
    }
    
    // Credit block.
    acf_register_block_type(array(
        'name'              => 'credit',
        'title'             => 'Credit',
        'description'       => 'A custom credit block.',
        'category'          => 'text',
        'keywords' 			=> array('text', 'credit'),
        'icon'				=> 'editor-textcolor',
        'render_template'   => get_template_directory() . '/blocks/credit/block.php',
        'enqueue_style' 	=> get_template_directory_uri() . '/blocks/credit/block.css',
    ));
    
    // Scrolling Gallery
    acf_register_block_type(array(
        'name'              => 'scrolling-gallery',
        'title'             => 'Scrolling Gallery',
        'description'       => 'A side scrolling gallery block.',
        'category'          => 'media',
        'keywords' 			=> array('gallery', 'scrolling', 'image'),
        'icon'				=> 'images-alt',
        'render_template'   => get_template_directory() . '/blocks/scrolling-gallery/block.php',
        'enqueue_style' 	=> get_template_directory_uri() . '/blocks/scrolling-gallery/block.css',
    ));
    
    // Stats Block
    acf_register_block_type(array(
        'name'              => 'stats',
        'title'             => 'Stats',
        'description'       => 'A block used to show statistics.',
        'category'          => 'text',
        'keywords' 			=> array('statistics', 'numbers', 'count'),
        'icon'				=> 'info',
        'render_template'   => get_template_directory() . '/blocks/stats/block.php',
        'enqueue_style' 	=> get_template_directory_uri() . '/blocks/stats/block.css',
    ));  
    
    // Video Tray
    acf_register_block_type(array(
        'name'              => 'video-tray',
        'title'             => 'Video Tray',
        'description'       => 'A block to show multiple small Vimeo videos in a scrolling tray.',
        'category'          => 'media',
        'keywords' 			=> array('video', 'vimeo', 'scrolling'),
        'icon'				=> 'video-alt2',
        'render_template'   => get_template_directory() . '/blocks/video-tray/block.php',
        'enqueue_style' 	=> get_template_directory_uri() . '/blocks/video-tray/block.css',
    ));
    
    // Press Links
    acf_register_block_type(array(
        'name'              => 'links',
        'title'             => 'Links',
        'description'       => 'A block to show multiple links to press articles.',
        'category'          => 'widgets',
        'keywords' 			=> array('press', 'links', 'article'),
        'icon'				=> 'admin-links',
        'render_template'   => get_template_directory() . '/blocks/links/block.php',
        'enqueue_style' 	=> get_template_directory_uri() . '/blocks/links/block.css',
    ));
    
    // Awards
    acf_register_block_type(array(
        'name'              => 'awards',
        'title'             => 'Awards',
        'description'       => 'A block to show Awards.',
        'category'          => 'widgets',
        'keywords' 			=> array('awards', 'links'),
        'icon'				=> 'awards',
        'render_template'   => get_template_directory() . '/blocks/awards/block.php',
        'enqueue_style' 	=> get_template_directory_uri() . '/blocks/awards/block.css',
    ));
    
    // Video with badge 
    acf_register_block_type(array(
        'name'              => 'video-with-badge',
        'title'             => 'Video with Badge',
        'description'       => 'A block to to embed a video, with a badge in the top corner.',
        'category'          => 'media',
        'keywords' 			=> array('video', 'badge', 'vimeo'),
        'icon'				=> 'video-alt3',
        'render_template'   => get_template_directory() . '/blocks/video-with-badge/block.php',
        'enqueue_style' 	=> get_template_directory_uri() . '/blocks/video-with-badge/block.css',
    ));    

}
add_action('acf/init', 'fuxt_custom_blocks');

@julienkos
Copy link
Author

Hi Drew, thank you for the continued support. I tried using some of your code and it works until I add a field to it. I've made a short video showing you what happens.

https://www.loom.com/share/493b4b56cd734e13996ee4c707a28237

I also thought it might be beneficial for me to add a list of my plugins in case you think any of these might be causing issues. I'm not sure which ones you are using along side yours.

  • Add WPGraphQL SEO - Version 4.16.2
  • Advanced Custom Fields PRO - Version 5.12
  • Contact Form 7 - Version 5.5.6
  • Headless Block Parser - Version 0.1.0
  • WP GQL Gutenberg - Version 0.3.11
  • WP GraphQL - Version 1.7.2
  • WPGraphQL for Advanced Custom Fields - Version 0.5.3
  • WPGraphQL JWT Authentication - Version 0.4.0
  • WPGraphQL WPML - Version 1.1.0
  • WPML Multilingual CMS - Version 4.5.5
  • WPML SEO - Version 2.0.1
  • Yoast SEO - Version 18.4.1

I've tried deactivating everything except for the 4 required (your plugin, graphql, acf graphql, and acf pro) but it still causes the same error. Let me know what you think. I will try creating a fresh install and seeing if it happens to me there as well.

@b00y0h
Copy link

b00y0h commented Dec 1, 2022

any update on this? I'm having the exact same issue.

@rsm0128
Copy link
Collaborator

rsm0128 commented Dec 28, 2022

I can't replicate the same issue on my side.
@julienkos @b00y0h Do you still have the issue with the latest version?

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

4 participants