PluginProbe
Booking Calendar / 11.9
Booking Calendar v11.9
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-setup-wizard / step-date-time-formats / class-wpbc-setup-wizard-date-time-formats-module.php

class-wpbc-setup-wizard-date-time-formats-module.php in Booking Calendar 11.9, at includes/page-setup-wizard/step-date-time-formats/class-wpbc-setup-wizard-date-time-formats-module.php

169 lines 5.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Reusable module adapter for the Dates and times setup editor.
4 *
5 * @package Booking Calendar
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 /**
13 * Expose Step 3 through the common setup-module contract.
14 */
15 final class WPBC_Setup_Wizard_Date_Time_Formats_Module implements WPBC_Setup_Wizard_Step_Module, WPBC_Setup_Wizard_Current_Values_Module {
16
17 /** @var WPBC_Setup_Wizard_Date_Time_Formats */
18 private $date_time_formats;
19
20 /**
21 * Build the adapter around the reusable domain service.
22 *
23 * @param WPBC_Setup_Wizard_Date_Time_Formats|null $date_time_formats Optional service for tests or composition.
24 */
25 public function __construct( $date_time_formats = null ) {
26 $this->date_time_formats = $date_time_formats instanceof WPBC_Setup_Wizard_Date_Time_Formats
27 ? $date_time_formats
28 : new WPBC_Setup_Wizard_Date_Time_Formats();
29 }
30
31 /**
32 * Return the stable module and step identifier.
33 *
34 * @return string Stable identifier.
35 */
36 public function get_step_id() {
37 return 'date_time_formats';
38 }
39
40 /**
41 * Return the rail and template metadata contributed by this module.
42 *
43 * @return array{id:string,label:string,template:string} Step definition.
44 */
45 public function get_step_definition() {
46 return array(
47 'id' => $this->get_step_id(),
48 'label' => __( 'Dates & times', 'booking' ),
49 'template' => 'step-date-time-formats',
50 );
51 }
52
53 /**
54 * Return the absolute server-owned template path.
55 *
56 * @return string Absolute template path.
57 */
58 public function get_template_path() {
59 return __DIR__ . '/template.php';
60 }
61
62 /**
63 * Return the ordered draft fields accepted by Step 3.
64 *
65 * @return string[] Field allow-list.
66 */
67 public function get_field_names() {
68 return $this->date_time_formats->get_field_names();
69 }
70
71 /**
72 * Return fields required when advancing.
73 *
74 * @return string[] Required field identifiers.
75 */
76 public function get_required_fields() {
77 return $this->date_time_formats->get_required_fields();
78 }
79
80 /**
81 * Return current settings or safe read-only suggestions.
82 *
83 * @return array<string,string> Initial field values.
84 */
85 public function get_initial_values() {
86 return $this->date_time_formats->get_initial_values();
87 }
88
89 /**
90 * Refresh every date and time preference from canonical plugin options.
91 *
92 * @return string[] Current-value field identifiers.
93 */
94 public function get_current_value_field_names() {
95 return $this->get_field_names();
96 }
97
98 /**
99 * Return dependencies required to render this module.
100 *
101 * @return string[] No cross-step dependencies.
102 */
103 public function get_context_dependencies() {
104 return array();
105 }
106
107 /**
108 * Build the data-only Step 3 context.
109 *
110 * @param array<string,mixed> $field_values Validated module fields.
111 * @param array<string,mixed> $consumer_context Unused consumer context.
112 *
113 * @return array<string,mixed> Authorized presentation context.
114 */
115 public function get_context( array $field_values, array $consumer_context = array() ) {
116 unset( $consumer_context );
117
118 return $this->date_time_formats->get_context( $field_values );
119 }
120
121 /**
122 * Validate one Step 3 draft field.
123 *
124 * @param string $field_id Stable field identifier.
125 * @param mixed $raw_value Untrusted submitted value.
126 * @param bool $is_required Whether an empty value is invalid.
127 *
128 * @return string|WP_Error Normalized value or an error.
129 */
130 public function validate_field( $field_id, $raw_value, $is_required ) {
131 return $this->date_time_formats->validate_field( $field_id, $raw_value, $is_required );
132 }
133
134 /**
135 * Enqueue compiled Step 3 assets and request metadata.
136 *
137 * @param string $module_url Absolute URL to the Setup Wizard module root.
138 * @param string|false $asset_version Plugin version used for cache busting.
139 * @param string $shared_style_handle Consumer shell style handle.
140 * @param string $shared_script_handle Consumer shell script handle.
141 *
142 * @return void
143 */
144 public function enqueue_assets( $module_url, $asset_version, $shared_style_handle, $shared_script_handle ) {
145 $module_url = trailingslashit( $module_url );
146
147 wp_enqueue_style( 'wpbc-setup-wizard-date-time-formats', $module_url . 'step-date-time-formats/_out/step-date-time-formats.css', array( $shared_style_handle ), $asset_version );
148 wp_enqueue_script( 'wpbc-setup-wizard-date-time-formats', $module_url . 'step-date-time-formats/_out/step-date-time-formats.js', array( $shared_script_handle, 'jquery' ), $asset_version, true );
149 wp_localize_script(
150 'wpbc-setup-wizard-date-time-formats',
151 'wpbc_setup_wizard_date_time_formats',
152 array(
153 'ajax_url' => admin_url( 'admin-ajax.php' ),
154 'action' => WPBC_Setup_Wizard_Date_Time_Formats_Ajax::ACTION_INSTALL_LOCAL_TRANSLATION,
155 'nonce' => wp_create_nonce( WPBC_Setup_Wizard_Ajax::NONCE_ACTION ),
156 'i18n' => array(
157 'working' => __( 'Downloading and updating Local translations...', 'booking' ),
158 'connecting' => __( 'Connecting to the official Booking Calendar translation archive.', 'booking' ),
159 'complete' => __( 'Update complete', 'booking' ),
160 'reloading' => __( 'Reloading the page to activate the updated translation...', 'booking' ),
161 'failed' => __( 'Update failed', 'booking' ),
162 'error' => __( 'Local translations could not be updated. Try again or use the Translations settings page.', 'booking' ),
163 'local_source_label' => __( 'Local', 'booking' ),
164 ),
165 )
166 );
167 }
168 }
169