reset(); acf_get_store( 'field-groups' )->reset(); } } // Disable ACF / ACFE modules add_action( 'acf/init', 'ccat_acf_init' ); function ccat_acf_init() { acf_update_setting( 'acfe/modules/block_types', false ); acf_update_setting( 'acfe/modules/categories', false ); acf_update_setting( 'acfe/modules/forms', false ); acf_update_setting( 'acfe/modules/options_pages', false ); acf_update_setting( 'acfe/modules/post_types', false ); acf_update_setting( 'acfe/modules/taxonomies', false ); acf_update_setting( 'acfe/modules/templates', false ); } // Helper: Get GraphQL field group name for flexible content layout function ccat_get_graphql_layout_typename( $field_group_key, $layout_name ) { $layout_type_name = \WPGraphQL\Utils\Utils::format_type_name( $layout_name ); return "GroupAbstractBuilderSections{$layout_type_name}Layout"; } // Helper: Convert field name to GraphQL format function ccat_get_graphql_field_name( $field_config ) { return ! empty( $field_config['graphql_field_name'] ) ? $field_config['graphql_field_name'] : \WPGraphQL\Utils\Utils::format_field_name( $field_config['name'], false ); } // Helper: Convert field data to GraphQL format recursively function ccat_get_graphql_fields_value( $fields, $data ) { $result = array(); foreach ( $fields as $field ) { $key = ccat_get_graphql_field_name( $field ); $value = $data[ $field['name'] ] ?? null; if ( $value && isset( $field['sub_fields'] ) ) { $value = is_array( $value[0] ?? null ) ? array_map( fn( $row ) => ccat_get_graphql_fields_value( $field['sub_fields'], $row ), $value ) : ccat_get_graphql_fields_value( $field['sub_fields'], $value ); } $result[ $key ] = $value; } return $result; } // Helper: Get current row's preview data in useSection format function ccat_get_graphql_preview_data() { if ( empty( $layout_name = get_row_layout() ) ) { throw new Exception( "Erreur de prévisualisation (section invalide)" ); } $result = array( '__typename' => ccat_get_graphql_layout_typename( 'group_abstract_builder', $layout_name ), ); $format_value = $result['__typename'] !== 'GroupAbstractBuilderSectionsTemplateLayout'; foreach ( get_row( $format_value ) ?: array() as $key => $value ) { if ( strpos( $key, 'acf_fc_layout' ) !== 0 && strpos( $key, '_' ) !== 0 ) { $result[ ccat_get_graphql_field_name( array( 'name' => $key ) ) ] = $value; } } return $result; }