PluginProbe
Booking Calendar / 11.2
Booking Calendar v11.2
11.9 11.8.4 11.8.3 11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 All 205 releases
booking / includes / page-form-builder / field-packs / steps-timeline / field-steps-timeline.php

field-steps-timeline.php in Booking Calendar 11.2, at includes/page-form-builder/field-packs/steps-timeline/field-steps-timeline.php

183 lines 7.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WPBC BFB Pack: Steps Timeline (Wizard Progress Indicator) — Schema-driven, Factory Inspector
4 *
5 * Purpose:
6 * - Adds a visual progress indicator for multi-step (wizard) forms.
7 * - One pack type "steps_timeline" with props: steps_count, active_step, color, cssclass_extra/html_id/help.
8 * - Inspector is Factory-driven (no WP templates). Preview is rendered by a pure JS renderer class.
9 * - Optional exporter hook (JS) emits shortcode: [steps_timeline steps_count="N" active_step="X" color="#HEX"]
10 * Note: shortcode name intentionally matches legacy typo "steps_timeline" used in advanced form mode.
11 *
12 * Contracts Used:
13 * - Filter: wpbc_bfb_register_field_packs
14 * - Action: wpbc_enqueue_js_field_pack
15 * - Action: wpbc_bfb_palette_register_items (optional palette registration)
16 *
17 * Files:
18 * ../includes/page-form-builder/field-packs/steps-timeline/field-steps-timeline.php (this file)
19 * ../includes/page-form-builder/field-packs/steps-timeline/_out/steps-timeline.js (renderer + exporter glue)
20 *
21 * @package Booking Calendar
22 * @author wpdevelop
23 * @since 11.0.0
24 * @modified 2025-11-07
25 * @version 1.0.1
26 */
27
28 if ( ! defined( 'ABSPATH' ) ) {
29 exit;
30 }
31
32 /**
33 * Register the "steps_timeline" field pack (Schema-driven Inspector).
34 *
35 * Props stored in schema (coercion/validation is handled by Inspector/Factory):
36 * - steps_count : int 2..12 (default 3) — total number of steps (nodes)
37 * - active_step : int 1..steps_count (default 1) — currently active step (1-based)
38 * - color : string CSS color (default '#619d40') — line and active/completed dot color
39 * - cssclass_extra : string optional extra CSS classes
40 * - html_id : string optional HTML id
41 * - help : string optional help text (Inspector-only)
42 *
43 * Inspector UI notes:
44 * - "name" control is intentionally hidden/omitted (not needed for this non-input visual element).
45 *
46 * @param array $packs Accumulated packs.
47 * @return array Modified packs with "steps_timeline" field included.
48 */
49 function wpbc_bfb_register_field_packs__field_steps_timeline_schema( $packs ) {
50
51 $packs['steps_timeline'] = array(
52 'kind' => 'field',
53 'type' => 'steps_timeline',
54 'label' => __( 'Steps Timeline', 'booking' ),
55 'icon' => 'clock',
56 'usage_key' => 'steps_timeline',
57
58 // === Schema: coercion/validation + defaults for Inspector/serialization ===
59 'schema' => array(
60 'props' => array(
61 'steps_count' => array( 'type' => 'int', 'min' => 2, 'max' => 12, 'default' => 3 ),
62 'active_step' => array( 'type' => 'int', 'min' => 1, 'max' => 12, 'default' => 1 ),
63 'color' => array( 'type' => 'string', 'default' => '#619d40' ),
64 'cssclass_extra' => array( 'type' => 'string', 'default' => '' ),
65 'html_id' => array( 'type' => 'string', 'default' => '' ),
66 'help' => array( 'type' => 'string', 'default' => '' ),
67 // "name" is supported in storage but hidden in Inspector to avoid confusion.
68 'name' => array( 'type' => 'string', 'default' => '' ),
69 ),
70 ),
71
72 // === Inspector UI (Factory-driven; no WP templates here) ===
73 'inspector_ui' => array(
74 'title' => __( 'Steps Timeline', 'booking' ),
75 'description' => __( 'Configure a multi-step progress indicator for wizard-style forms.', 'booking' ),
76 'header_variant' => 'toolbar',
77 'header_actions' => array( 'deselect', 'scrollto', 'move-up', 'move-down', 'duplicate', 'delete' ),
78 'groups' => array(
79 array(
80 'key' => 'basic',
81 'label' => __( 'Basic', 'booking' ),
82 'open' => true,
83 'controls' => array(
84 array(
85 'type' => 'range_number',
86 'key' => 'steps_count',
87 'label' => __( 'Steps Count', 'booking' ),
88 'min' => 2,
89 'max' => 12,
90 'step' => 1,
91 'help' => __( 'Total number of steps (2–12).', 'booking' ),
92 ),
93 array(
94 'type' => 'range_number',
95 'key' => 'active_step',
96 'label' => __( 'Active Step', 'booking' ),
97 'min' => 1,
98 'max' => 12,
99 'step' => 1,
100 'help' => __( 'Currently highlighted step (1-based). Will be clamped to Steps Count.', 'booking' ),
101 ),
102 array(
103 'type' => 'color',
104 'key' => 'color',
105 'label' => __( 'Color', 'booking' ),
106 'placeholder' => '#619d40',
107 ),
108 ),
109 ),
110 array(
111 'key' => 'advanced',
112 'label' => __( 'Advanced', 'booking' ),
113 'controls' => array(
114 array( 'type' => 'text', 'key' => 'cssclass_extra', 'label' => __( 'Extra CSS classes', 'booking' ) ),
115 // "name" intentionally omitted from Inspector
116 array( 'type' => 'text', 'key' => 'html_id', 'label' => __( 'HTML ID', 'booking' ) ),
117 array( 'type' => 'textarea', 'key' => 'help', 'label' => __( 'Help text', 'booking' ), 'rows' => 3 ),
118 ),
119 ),
120 ),
121 ),
122 );
123
124 return $packs;
125 }
126 add_filter( 'wpbc_bfb_register_field_packs', 'wpbc_bfb_register_field_packs__field_steps_timeline_schema' );
127
128 /**
129 * Enqueue the Steps Timeline field pack assets for the Builder page.
130 *
131 * Notes:
132 * - The JS file implements the 'steps_timeline' renderer (and safe exporter glue).
133 * - CSS file is optional — the JS injects a minimal fallback for preview if not present.
134 *
135 * @param string $page Current admin page slug (unused, provided for parity with other packs).
136 * @return void
137 */
138 function wpbc_bfb_enqueue__field_steps_timeline_assets( $page ) {
139
140 wp_enqueue_script(
141 'wpbc-bfb_field_steps_timeline',
142 wpbc_plugin_url( '/includes/page-form-builder/field-packs/steps-timeline/_out/steps-timeline.js' ),
143 array( 'wpbc-bfb' ),
144 WP_BK_VERSION_NUM,
145 true
146 );
147 }
148 add_action( 'wpbc_enqueue_js_field_pack', 'wpbc_bfb_enqueue__field_steps_timeline_assets', 10, 1 );
149
150 /**
151 * (Optional) Register a ready-to-use palette item in "structure/bottom".
152 *
153 * Data hints allow initializing defaults without templates:
154 * data-steps_count="3"
155 * data-active_step="1"
156 * data-color="#619d40"
157 * data-usagenumber="1" (limit: one per page; requires UsageLimitService aggregation by usage_key)
158 *
159 * @param string $group Palette group: 'general' | 'advanced' | 'structure' | ...
160 * @param string $position Position: 'top' | 'bottom'
161 * @return void
162 */
163 function wpbc_bfb_palette_register_items__steps_timeline_schema( $group, $position ) {
164
165 if ( 'navigation' !== $group || 'top' !== $position ) {
166 return;
167 }
168 ?>
169 <li class="wpbc_bfb__field"
170 data-id="steps_timeline"
171 data-type="steps_timeline"
172 data-usage_key="steps_timeline"
173 data-steps_count="3"
174 data-active_step="1"
175 data-color="#619d40">
176 <i class="menu_icon icon-1x wpbc-bi-segmented-nav"></i>
177 <span class="wpbc_bfb__field-label"><?php echo esc_html( __( 'Steps Timeline', 'booking' ) ); ?></span>
178 <span class="wpbc_bfb__field-type">steps_timeline</span>
179 </li>
180 <?php
181 }
182 add_action( 'wpbc_bfb_palette_register_items', 'wpbc_bfb_palette_register_items__steps_timeline_schema', 10, 2 );
183