| 1 |
<?php |
| 2 |
/** |
| 3 |
* WPBC BFB Pack: Wizard Navigation Button (Back / Next) — Schema-driven, Factory Inspector |
| 4 |
* |
| 5 |
* Purpose: |
| 6 |
* - Adds a field pack that renders a "Back" or "Next" button to move between booking form pages (wizard steps). |
| 7 |
* - Strictly keeps the required front-end classes so external scripts can handle navigation: |
| 8 |
* <a class="wpbc_button_light wpbc_wizard_step_button wpbc_wizard_step_{N}">Label</a> |
| 9 |
* - The trailing number in "wpbc_wizard_step_{N}" defines the destination page (1-based). |
| 10 |
* - No WP templates for Inspector; preview is rendered by a pure JS renderer class. |
| 11 |
* - Keep schema defaults in sync with JS get_defaults(). |
| 12 |
* |
| 13 |
* Contracts Used: |
| 14 |
* - Filter: wpbc_bfb_register_field_packs |
| 15 |
* - Action: wpbc_enqueue_js_field_pack |
| 16 |
* - Action: wpbc_bfb_palette_register_items (optional palette registration) |
| 17 |
* |
| 18 |
* File: ../includes/page-form-builder/field-packs/wizard-nav/field-wizard-nav.php |
| 19 |
* |
| 20 |
* @package Booking Calendar |
| 21 |
* @author wpdevelop, oplugins |
| 22 |
* @since 11.0.0 |
| 23 |
* @modified 2025-09-22 |
| 24 |
* @version 1.0.0 |
| 25 |
*/ |
| 26 |
|
| 27 |
if ( ! defined( 'ABSPATH' ) ) { |
| 28 |
exit; |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Register the "wizard_nav" field pack (Schema-driven Inspector). |
| 33 |
* |
| 34 |
* Props stored in schema (coercion/validation handled by Inspector/Factory): |
| 35 |
* - direction : string 'next' | 'back' (default 'next') |
| 36 |
* - label : string Visible text (default depends on direction) |
| 37 |
* - target_step : int Destination page number, >= 1 (default 2 for 'next', 1 for 'back') |
| 38 |
* - cssclass_extra : string Optional extra CSS classes (required classes added by renderer) |
| 39 |
* - name : string Optional internal name |
| 40 |
* - html_id : string Optional HTML id |
| 41 |
* - help : string Optional help text (Inspector-only aid) |
| 42 |
* |
| 43 |
* @param array $packs Accumulated packs. |
| 44 |
* |
| 45 |
* @return array Modified packs with "wizard_nav" field included. |
| 46 |
*/ |
| 47 |
function wpbc_bfb_register_field_packs__field_wizard_nav_schema( $packs ) { |
| 48 |
|
| 49 |
$packs['wizard_nav'] = array( |
| 50 |
'kind' => 'field', |
| 51 |
'type' => 'wizard_nav', |
| 52 |
'label' => __( 'Wizard Button', 'booking' ), |
| 53 |
'icon' => 'admin-links', |
| 54 |
'usage_key' => 'wizard_nav', |
| 55 |
|
| 56 |
// === Schema: coercion/validation + defaults for Inspector/serialization === |
| 57 |
'schema' => array( |
| 58 |
'props' => array( |
| 59 |
'direction' => array( 'type' => 'enum', 'values' => array( 'next', 'back' ), 'default' => 'next' ), |
| 60 |
'label' => array( 'type' => 'string', 'default' => __( 'Next', 'booking' ) ), |
| 61 |
'target_step' => array( 'type' => 'int', 'min' => 1, 'default' => 2 ), |
| 62 |
'cssclass_extra' => array( 'type' => 'string', 'default' => '' ), |
| 63 |
// 'name' => array( 'type' => 'string', 'default' => '' ), |
| 64 |
'html_id' => array( 'type' => 'string', 'default' => '' ), |
| 65 |
'help' => array( 'type' => 'string', 'default' => '' ), |
| 66 |
), |
| 67 |
), |
| 68 |
|
| 69 |
// === Inspector UI (Factory-driven; no WP templates here) === |
| 70 |
'inspector_ui' => array( |
| 71 |
'title' => __( 'Wizard Button', 'booking' ), |
| 72 |
'description' => __( 'Configure a Back/Next button that moves between wizard pages.', 'booking' ), |
| 73 |
'header_variant' => 'toolbar', |
| 74 |
'header_actions' => array( 'deselect', 'scrollto', 'move-up', 'move-down', 'duplicate', 'delete' ), |
| 75 |
'groups' => array( |
| 76 |
array( |
| 77 |
'key' => 'basic', |
| 78 |
'label' => __( 'Basic', 'booking' ), |
| 79 |
'open' => true, |
| 80 |
'controls' => array( |
| 81 |
array( |
| 82 |
'type' => 'select', |
| 83 |
'key' => 'direction', |
| 84 |
'label' => __( 'Direction', 'booking' ), |
| 85 |
'options' => array( |
| 86 |
array( 'value' => 'next', 'label' => __( 'Next', 'booking' ) ), |
| 87 |
array( 'value' => 'back', 'label' => __( 'Back', 'booking' ) ), |
| 88 |
), |
| 89 |
'help' => __( 'Choose whether this button moves forward or backward.', 'booking' ), |
| 90 |
), |
| 91 |
array( 'type' => 'text', 'key' => 'label', 'label' => __( 'Label', 'booking' ) ), |
| 92 |
array( 'type' => 'number', 'key' => 'target_step', 'label' => __( 'Target Step (page #)', 'booking' ), 'min' => 1, 'step' => 1 ), |
| 93 |
), |
| 94 |
), |
| 95 |
array( |
| 96 |
'key' => 'appearance', |
| 97 |
'label' => __( 'Advanced', 'booking' ), |
| 98 |
'controls' => array( |
| 99 |
array( 'type' => 'text', 'key' => 'cssclass_extra', 'label' => __( 'Extra CSS classes', 'booking' ) ), |
| 100 |
// array( 'type' => 'text', 'key' => 'name', 'label' => __( 'Name', 'booking' ) ), |
| 101 |
array( 'type' => 'text', 'key' => 'html_id', 'label' => __( 'HTML ID', 'booking' ) ), |
| 102 |
array( 'type' => 'textarea', 'key' => 'help', 'label' => __( 'Help text', 'booking' ), 'rows' => 3 ), |
| 103 |
), |
| 104 |
), |
| 105 |
), |
| 106 |
/** |
| 107 |
* Implementation notes for renderer: |
| 108 |
* - Always include required classes: |
| 109 |
* "wpbc_button_light wpbc_wizard_step_button wpbc_wizard_step_{N}" |
| 110 |
* - Append cssclass_extra after required classes. |
| 111 |
* - Do not allow removing required classes via Inspector. |
| 112 |
*/ |
| 113 |
), |
| 114 |
|
| 115 |
// No templates_printer for Schema-driven variant. |
| 116 |
); |
| 117 |
|
| 118 |
return $packs; |
| 119 |
} |
| 120 |
add_filter( 'wpbc_bfb_register_field_packs', 'wpbc_bfb_register_field_packs__field_wizard_nav_schema' ); |
| 121 |
|
| 122 |
|
| 123 |
/** |
| 124 |
* Enqueue the Wizard Navigation field pack JS for the Builder page. |
| 125 |
* |
| 126 |
* This hook is fired only on the Builder page (gated by is_builder_by_request()). |
| 127 |
* The JS file must implement the 'wizard_nav' renderer and respect required classes: |
| 128 |
* <a class="wpbc_button_light wpbc_wizard_step_button wpbc_wizard_step_{N}">Label</a> |
| 129 |
* |
| 130 |
* @param string $page Current admin page slug. |
| 131 |
* |
| 132 |
* @return void |
| 133 |
*/ |
| 134 |
function wpbc_bfb_enqueue__field_wizard_nav_schema_js( $page ) { |
| 135 |
|
| 136 |
wp_enqueue_script( |
| 137 |
'wpbc-bfb_field_wizard_nav_schema', |
| 138 |
wpbc_plugin_url( '/includes/page-form-builder/field-packs/wizard-nav/_out/wizard-nav.js' ), |
| 139 |
array( 'wpbc-bfb' ), |
| 140 |
WP_BK_VERSION_NUM, |
| 141 |
true |
| 142 |
); |
| 143 |
} |
| 144 |
add_action( 'wpbc_enqueue_js_field_pack', 'wpbc_bfb_enqueue__field_wizard_nav_schema_js', 10, 1 ); |
| 145 |
|
| 146 |
|
| 147 |
/** |
| 148 |
* (Optional) Register the "Next" and "Back" palette items in "general/bottom". |
| 149 |
* |
| 150 |
* If your palette auto-builds from packs, you can remove this. |
| 151 |
* Notes: |
| 152 |
* - We provide flat data-* hints so the builder can initialize presets without templates: |
| 153 |
* data-direction="next|back" data-target_step="N" data-label="..." |
| 154 |
* - Required classes are added by the JS renderer; do not include them here. |
| 155 |
* |
| 156 |
* @param string $group Palette group: 'general' | 'advanced' | ... |
| 157 |
* @param string $position Position: 'top' | 'bottom' |
| 158 |
* |
| 159 |
* @return void |
| 160 |
*/ |
| 161 |
function wpbc_bfb_palette_register_items__wizard_nav_schema( $group, $position ) { |
| 162 |
|
| 163 |
if ( 'navigation' !== $group || 'top' !== $position ) { |
| 164 |
return; |
| 165 |
} |
| 166 |
?> |
| 167 |
<li class="wpbc_bfb__field" |
| 168 |
data-id="wizard_nav_back" |
| 169 |
data-type="wizard_nav" |
| 170 |
data-usage_key="wizard_nav" |
| 171 |
data-direction="back" |
| 172 |
data-target_step="1" |
| 173 |
data-label="<?php echo esc_attr( __( 'Back', 'booking' ) ); ?>"> |
| 174 |
<i class="menu_icon icon-1x wpbc_icn_arrow_back"></i> |
| 175 |
<span class="wpbc_bfb__field-label"><?php echo esc_html( __( 'Back Button', 'booking' ) ); ?></span> |
| 176 |
<span class="wpbc_bfb__field-type">Wizard Buttons</span> |
| 177 |
</li> |
| 178 |
<li class="wpbc_bfb__field" |
| 179 |
data-id="wizard_nav_next" |
| 180 |
data-type="wizard_nav" |
| 181 |
data-usage_key="wizard_nav" |
| 182 |
data-direction="next" |
| 183 |
data-target_step="2" |
| 184 |
data-label="<?php echo esc_attr( __( 'Next', 'booking' ) ); ?>"> |
| 185 |
<i class="menu_icon icon-1x wpbc_icn_arrow_forward"></i> |
| 186 |
<span class="wpbc_bfb__field-label"><?php echo esc_html( __( 'Next Button', 'booking' ) );; ?></span> |
| 187 |
<span class="wpbc_bfb__field-type">Wizard Buttons</span> |
| 188 |
</li> |
| 189 |
<?php |
| 190 |
} |
| 191 |
add_action( 'wpbc_bfb_palette_register_items', 'wpbc_bfb_palette_register_items__wizard_nav_schema', 10, 2 ); |
| 192 |
|