wp-graphql / wpgraphql-acf

Re-architecture of WPGraphQL for ACF
GNU General Public License v3.0
91 stars 12 forks source link

ACF Options page fields #199

Open BogdanKozhevnik opened 7 months ago

BogdanKozhevnik commented 7 months ago

Description

1) in the old plugin I can only register the options page manually, WPGraphQL for Advanced Custom Fields does not add the page to the graphql schema. However manually it works and I can create acf fields and add them to the page. I completely disable Polylang synchronization for acf and only use the language switcher for the options page. Fields store different values according to language, and so does the result by language during GraphQL queries. It works fine with the old plugin. However, there is another problem, I created a Gutenberg block with acf fields, but in the GraphQL response I get an incorrect data schema even if I use my own render template.

function acf_blocks() {
    if( function_exists('acf_register_block') ) {
        acf_register_block(array(
            'name'              => 'banner',
            'title'             => __('Banner'),
            'description'       => __('A custom banner block.'),
            'category'          => 'formatting',
            'render_template'   => 'template-parts/blocks/banner.php',
            'icon'              => 'dashicons-embed-photo',
            'keywords'          => array( 'banner', 'photos' ),
        ));
    }
}

/**
 * Block Name: Banner
 */
$title = get_field('title') ?: 'Title;
$text = get_field('text') ?: 'Text';
$image = get_field('image') ?: 'Image';
?>
<style>
    .banner {
        border: 1px solid #e0e0e0;
        border-radius: 5px;
        margin-bottom: 20px;
    }
</style>
<div class="banner">
    <h2><?php echo $title; ?></h2>
    <p><?php echo $text; ?></p>
    <?php if( $image ): ?>
        <img src="<?php echo esc_url($image['url']); ?>" alt="<?php echo esc_attr($image['alt']); ?>" />
    <?php endif; ?>
</div>

Then i put it to the post and try to get blocks.

query GetPosts {
  posts(where: {language: EN}) {
    nodes {
      blocksJSON
    }
  }
}

image As you can see, the image contains only the id, although the acf image field contains both the title and the link.

2) But with the new plugin the situation is even more complicated. Now it adds the options pages to the grapgl schema, but it is not possible to get the fields according to the language. The schema doesn't even show the language argument with LanguageCodeEnum. It only appears if this page is added via code:

acf_add_options_page(array(
    'page_title' => 'Blog Settings',
    'menu_title' => 'Blog Settings',
    'menu_slug' => 'blog',
    'capability' => 'edit_posts',
    'redirect' => false,
    'show_in_graphql' => true,
    'graphql_field_name' => 'blog',
));

,but still doesn't work. And although the fields on the options page store different values ​​for different languages, you can't get them by language. It always return either the default value or null.

List of my plugins: image

fields on options page image

query image

acf Fields image

Steps to reproduce

Just try to get ACF Options Page fields by locale Just try to get fields from acf gutenberg block by locale

PHP or JSON export of the ACF Field Group(s)

acf-export-2024-04-21.json

Additional context

No response

WPGraphQL Version

1.23.0

WPGraphQL For ACF Version

old 0.6.1 beta 2, new 2.2.0

ACF (Advanced Custom Fields) Version. Free or Pro?

6.2.9 pro

WordPress Version

6.5.2

PHP Version

8.1

Additional enviornment details

No response

Please confirm that you have searched existing issues in the repo.

Please confirm that you have disabled ALL plugins except for WPGraphQL, WPGraphQL For ACF, ACF, etc.

BogdanKozhevnik commented 6 months ago

hi, do you need some additional information to reproduce bug? I can write it step-by-step