generated from pascalmartineau/wp-skeleton
feat: template replacement
Some checks failed
Deploy WordPress and Nuxt / deploy (push) Has been cancelled
Some checks failed
Deploy WordPress and Nuxt / deploy (push) Has been cancelled
This commit is contained in:
@@ -146,6 +146,7 @@ __( "Start date / time", 'ccat' );
|
||||
__( "Start month", 'ccat' );
|
||||
__( "Subject", 'ccat' );
|
||||
__( "Target audience", 'ccat' );
|
||||
__( "Template", 'ccat' );
|
||||
__( "Term – Discipline", 'ccat' );
|
||||
__( "Text block", 'ccat' );
|
||||
__( "This event is asynchronous", 'ccat' );
|
||||
|
||||
@@ -116,6 +116,68 @@
|
||||
"acfe_flexible_category": false,
|
||||
"acfe_layout_col": "auto",
|
||||
"acfe_layout_allowed_col": false
|
||||
},
|
||||
"layout_68d559a93813a": {
|
||||
"key": "layout_68d559a93813a",
|
||||
"name": "template",
|
||||
"label": "Template",
|
||||
"display": "block",
|
||||
"sub_fields": [
|
||||
{
|
||||
"key": "field_template_id",
|
||||
"label": "Template",
|
||||
"name": "template",
|
||||
"aria-label": "",
|
||||
"type": "post_object",
|
||||
"instructions": "",
|
||||
"required": 1,
|
||||
"conditional_logic": 0,
|
||||
"wrapper": {
|
||||
"width": "",
|
||||
"class": "",
|
||||
"id": ""
|
||||
},
|
||||
"post_type": [
|
||||
"template"
|
||||
],
|
||||
"post_status": "",
|
||||
"taxonomy": "",
|
||||
"return_format": "id",
|
||||
"multiple": 0,
|
||||
"max": "",
|
||||
"save_custom": 0,
|
||||
"save_post_status": "publish",
|
||||
"acfe_add_post": 0,
|
||||
"acfe_edit_post": 0,
|
||||
"acfe_bidirectional": {
|
||||
"acfe_bidirectional_enabled": "0"
|
||||
},
|
||||
"allow_null": 0,
|
||||
"allow_in_bindings": 0,
|
||||
"bidirectional": 0,
|
||||
"show_in_graphql": 1,
|
||||
"graphql_description": "",
|
||||
"graphql_field_name": "template",
|
||||
"graphql_connection_type": "one_to_many",
|
||||
"ui": 1,
|
||||
"bidirectional_target": [],
|
||||
"save_post_type": "",
|
||||
"min": ""
|
||||
}
|
||||
],
|
||||
"min": "",
|
||||
"max": "",
|
||||
"acfe_flexible_render_template": "",
|
||||
"acfe_flexible_render_style": "",
|
||||
"acfe_flexible_render_script": "",
|
||||
"acfe_flexible_modal_edit_size": "",
|
||||
"acfe_flexible_settings": "",
|
||||
"acfe_flexible_settings_size": "large",
|
||||
"acfe_flexible_thumbnail": false,
|
||||
"acfe_layout_locations": [],
|
||||
"acfe_flexible_category": false,
|
||||
"acfe_layout_col": "auto",
|
||||
"acfe_layout_allowed_col": false
|
||||
}
|
||||
},
|
||||
"min": "",
|
||||
@@ -159,5 +221,5 @@
|
||||
"graphql_types": "",
|
||||
"acfe_meta": "",
|
||||
"acfe_note": "",
|
||||
"modified": 1758740869
|
||||
"modified": 1758814061
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// Administration
|
||||
|
||||
// Core
|
||||
require_once __DIR__ . '/includes/core/sections.php';
|
||||
require_once __DIR__ . '/includes/core/theme-setup.php';
|
||||
|
||||
// Custom Post Types
|
||||
|
||||
45
wp-content/themes/ccat/includes/core/sections.php
Normal file
45
wp-content/themes/ccat/includes/core/sections.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
// Helper: Process sections and replace templates with their content
|
||||
function ccat_process_sections( $sections ) {
|
||||
if ( ! is_array( $sections ) ) {
|
||||
return $sections;
|
||||
}
|
||||
$processed_sections = array();
|
||||
foreach ( $sections as $section ) {
|
||||
// Check if this is a template section
|
||||
if ( isset( $section['acf_fc_layout'] ) && $section['acf_fc_layout'] === 'template' ) {
|
||||
$template_id = $section['template'] ?? null;
|
||||
if ( $template_id ) {
|
||||
$template_sections = get_field( 'sections', $template_id );
|
||||
if ( is_array( $template_sections ) ) {
|
||||
$expanded_sections = ccat_process_sections( $template_sections );
|
||||
foreach ( $expanded_sections as $expanded_section ) {
|
||||
$processed_sections[] = $expanded_section;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$processed_sections[] = $section;
|
||||
}
|
||||
}
|
||||
return $processed_sections;
|
||||
}
|
||||
|
||||
// Hook into ACF get_field to process sections
|
||||
add_filter( 'acf/format_value/name=sections', 'ccat_format_sections_value' );
|
||||
function ccat_format_sections_value( $value ) {
|
||||
if ( ! is_array( $value ) ) {
|
||||
return $value;
|
||||
}
|
||||
return ccat_process_sections( $value );
|
||||
}
|
||||
|
||||
// Hook into GraphQL to process sections when queried
|
||||
add_filter( 'graphql_acf_get_field_value', 'ccat_graphql_process_sections', 10, 2 );
|
||||
function ccat_graphql_process_sections( $value, $acf_field ) {
|
||||
if ( isset( $acf_field['name'] ) && $acf_field['name'] === 'sections' && is_array( $value ) ) {
|
||||
return ccat_process_sections( $value );
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
@@ -83,10 +83,11 @@ function ccat_get_graphql_preview_data() {
|
||||
if ( empty( $layout_name = get_row_layout() ) ) {
|
||||
throw new Exception( "Erreur de prévisualisation (section invalide)" );
|
||||
}
|
||||
$result = array(
|
||||
$result = array(
|
||||
'fieldGroupName' => ccat_get_graphql_field_group_name( 'group_abstract_builder', $layout_name ),
|
||||
);
|
||||
foreach ( get_row( true ) as $key => $value ) {
|
||||
$format_value = $result['fieldGroupName'] !== '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;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
<?php
|
||||
$preview_url = ( defined( 'NUXT_PUBLIC_SITE_URL' ) ? NUXT_PUBLIC_SITE_URL : 'https://cultureat.ca' ) . '/api/preview';
|
||||
$data = ccat_get_graphql_preview_data();
|
||||
$result = wp_remote_post( $preview_url, array( 'body' => $data ) );
|
||||
if ( $data['fieldGroupName'] === 'GroupAbstractBuilderSectionsTemplateLayout' ) {
|
||||
echo '<div style="font-weight: bold; padding: 16px;">' . get_the_title( $data['fieldTemplateId'] ) . '</div>';
|
||||
return;
|
||||
}
|
||||
$result = wp_remote_post( $preview_url, array( 'body' => $data ) );
|
||||
if ( is_wp_error( $result ) ) {
|
||||
echo '<div style="color: red;">Erreur: ' . esc_html( $result->get_error_message() ) . '</div>';
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user