feat: template replacement
Some checks failed
Deploy WordPress and Nuxt / deploy (push) Has been cancelled

This commit is contained in:
2025-09-25 11:31:39 -04:00
parent 9f4d110d6e
commit 3119f29218
7 changed files with 122 additions and 7 deletions

View File

@@ -149,10 +149,11 @@ Use GitHub-style checkboxes to mark task completion:
### ACF Extended Pro Preview System ### ACF Extended Pro Preview System
- [x] Configure ACF Extended Pro preview templates <!-- Completed: ACF Extended Pro installed --> - [x] Configure ACF Extended Pro preview templates <!-- Completed: ACF Extended Pro installed -->
- [ ] Set up iframe preview system <!-- Partial: layouts/ directory exists --> - [x] Set up iframe preview system <!-- Partial: layouts/ directory exists -->
- [ ] Implement SSR rendering for preview content <!-- Partial: Nuxt SSR configured --> - [x] Implement SSR rendering for preview content <!-- Partial: Nuxt SSR configured -->
- [x] Create preview layouts in `/layouts` directory <!-- Completed: layouts/ directory with files --> - [x] Create preview layouts in `/layouts` directory <!-- Completed: layouts/ directory with files -->
- [ ] Test real-time preview functionality - [x] Implement reusable template replacement logic
- [x] Test real-time preview functionality
### Content Features ### Content Features
- [ ] Implement image uploads with point-of-interest cropping - [ ] Implement image uploads with point-of-interest cropping

View File

@@ -146,6 +146,7 @@ __( "Start date / time", 'ccat' );
__( "Start month", 'ccat' ); __( "Start month", 'ccat' );
__( "Subject", 'ccat' ); __( "Subject", 'ccat' );
__( "Target audience", 'ccat' ); __( "Target audience", 'ccat' );
__( "Template", 'ccat' );
__( "Term &#8211; Discipline", 'ccat' ); __( "Term &#8211; Discipline", 'ccat' );
__( "Text block", 'ccat' ); __( "Text block", 'ccat' );
__( "This event is asynchronous", 'ccat' ); __( "This event is asynchronous", 'ccat' );

View File

@@ -116,6 +116,68 @@
"acfe_flexible_category": false, "acfe_flexible_category": false,
"acfe_layout_col": "auto", "acfe_layout_col": "auto",
"acfe_layout_allowed_col": false "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": "", "min": "",
@@ -159,5 +221,5 @@
"graphql_types": "", "graphql_types": "",
"acfe_meta": "", "acfe_meta": "",
"acfe_note": "", "acfe_note": "",
"modified": 1758740869 "modified": 1758814061
} }

View File

@@ -3,6 +3,7 @@
// Administration // Administration
// Core // Core
require_once __DIR__ . '/includes/core/sections.php';
require_once __DIR__ . '/includes/core/theme-setup.php'; require_once __DIR__ . '/includes/core/theme-setup.php';
// Custom Post Types // Custom Post Types

View 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;
}

View File

@@ -83,10 +83,11 @@ function ccat_get_graphql_preview_data() {
if ( empty( $layout_name = get_row_layout() ) ) { if ( empty( $layout_name = get_row_layout() ) ) {
throw new Exception( "Erreur de prévisualisation (section invalide)" ); 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 ), '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 ) { if ( strpos( $key, 'acf_fc_layout' ) !== 0 && strpos( $key, '_' ) !== 0 ) {
$result[ ccat_get_graphql_field_name( array( 'name' => $key ) ) ] = $value; $result[ ccat_get_graphql_field_name( array( 'name' => $key ) ) ] = $value;
} }

View File

@@ -1,7 +1,11 @@
<?php <?php
$preview_url = ( defined( 'NUXT_PUBLIC_SITE_URL' ) ? NUXT_PUBLIC_SITE_URL : 'https://cultureat.ca' ) . '/api/preview'; $preview_url = ( defined( 'NUXT_PUBLIC_SITE_URL' ) ? NUXT_PUBLIC_SITE_URL : 'https://cultureat.ca' ) . '/api/preview';
$data = ccat_get_graphql_preview_data(); $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 ) ) { if ( is_wp_error( $result ) ) {
echo '<div style="color: red;">Erreur: ' . esc_html( $result->get_error_message() ) . '</div>'; echo '<div style="color: red;">Erreur: ' . esc_html( $result->get_error_message() ) . '</div>';
} else { } else {