Backoffice
1 month ago
build_widget_data_attributes.php
1 month ago
get_widget_settings.php
1 month ago
load_script_file.php
1 month ago
load_script_template_file.php
1 month ago
load_translations.php
1 year ago
register_shortcode.php
1 month ago
sanitize_restaurant_id.php
1 month ago
sanitize_widget_settings.php
1 month ago
build_widget_data_attributes.php
53 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Zenchef\Widget\Widget; |
| 4 | |
| 5 | /** |
| 6 | * Builds the map of data-* attributes to emit on the .zc-widget-config element, |
| 7 | * given the plugin's settings array. Attributes for optional features are only |
| 8 | * included when explicitly enabled, so the SDK falls back to its own defaults |
| 9 | * (and to the Zenchef OS restaurant configuration) when the admin hasn't set |
| 10 | * anything. |
| 11 | * |
| 12 | * @param array $settings normalised settings (already sanitized) |
| 13 | * @return array<string, string> |
| 14 | */ |
| 15 | function build_widget_data_attributes(array $settings) |
| 16 | { |
| 17 | $attributes = [ |
| 18 | 'data-restaurant' => (string) ($settings['restaurant_id'] ?? ''), |
| 19 | 'data-position' => (string) ($settings['position'] ?? 'right'), |
| 20 | ]; |
| 21 | |
| 22 | $language = (string) ($settings['language'] ?? ''); |
| 23 | if ($language !== '') { |
| 24 | $attributes['data-lang'] = $language; |
| 25 | } |
| 26 | |
| 27 | $use_default_color = ($settings['use_default_color'] ?? '1') === '1'; |
| 28 | $primary_color = (string) ($settings['primary_color'] ?? ''); |
| 29 | if (!$use_default_color && $primary_color !== '') { |
| 30 | $attributes['data-primary-color'] = $primary_color; |
| 31 | } |
| 32 | |
| 33 | if (($settings['hide_button'] ?? '0') === '1') { |
| 34 | $attributes['data-hide-default-button'] = 'true'; |
| 35 | } |
| 36 | |
| 37 | $auto_open = ($settings['auto_open'] ?? '1') === '1'; |
| 38 | if (!$auto_open) { |
| 39 | $attributes['data-open'] = 'false'; |
| 40 | } else { |
| 41 | $attributes['data-open'] = (string) ($settings['open_delay'] ?? 3000); |
| 42 | } |
| 43 | |
| 44 | if (($settings['disable_gtm'] ?? '0') === '1') { |
| 45 | $attributes['data-disable-gtm'] = 'true'; |
| 46 | } |
| 47 | if (($settings['disable_ga4'] ?? '0') === '1') { |
| 48 | $attributes['data-disable-ga4'] = 'true'; |
| 49 | } |
| 50 | |
| 51 | return $attributes; |
| 52 | } |
| 53 |