| 1 |
<?php |
| 2 |
namespace MasterAddons\Inc\Admin\WidgetBuilder\Controls; |
| 3 |
|
| 4 |
defined('ABSPATH') || exit; |
| 5 |
|
| 6 |
/** |
| 7 |
* TEXT Control |
| 8 |
* Handles Elementor TEXT control type |
| 9 |
* |
| 10 |
* Supported properties from Control Settings Panel: |
| 11 |
* |
| 12 |
* EDIT TEXT SETTINGS: |
| 13 |
* - label: Control label |
| 14 |
* - name: Field name (used for control key) |
| 15 |
* - description: Description below field |
| 16 |
* - placeholder: Placeholder text |
| 17 |
* - default: Default value |
| 18 |
* |
| 19 |
* COMMON SETTINGS (handled by base class): |
| 20 |
* - show_label: Show/hide label (boolean) |
| 21 |
* - label_block: Display label on separate line (boolean) |
| 22 |
* - responsive: Enable responsive control (boolean) |
| 23 |
* - dynamic: Enable dynamic content support (boolean) |
| 24 |
* - separator: Control separator position (none/before/after) |
| 25 |
* |
| 26 |
* TEXT-SPECIFIC SETTINGS: |
| 27 |
* - input_type: HTML5 input type (text, url, email, tel, password, search, number) |
| 28 |
* - title: Tooltip text on hover |
| 29 |
* - classes: Custom CSS classes for control wrapper |
| 30 |
* |
| 31 |
* ADVANCED: |
| 32 |
* - condition: Conditional display logic (array) |
| 33 |
* - selectors: CSS selectors for styling (array) |
| 34 |
*/ |
| 35 |
class Text extends Control_Base { |
| 36 |
|
| 37 |
public function get_type() { |
| 38 |
return 'TEXT'; |
| 39 |
} |
| 40 |
|
| 41 |
public function build($control_key, $field) { |
| 42 |
$label = !empty($field['label']) ? $field['label'] : 'Text'; |
| 43 |
|
| 44 |
// Check if responsive control |
| 45 |
$is_responsive = isset($field['responsive']) && $field['responsive']; |
| 46 |
|
| 47 |
// Build control header (label + type + responsive) |
| 48 |
// If responsive=true, this will use add_responsive_control instead of add_control |
| 49 |
$content = $this->build_control_header($control_key, $label, 'TEXT', $is_responsive); |
| 50 |
|
| 51 |
// Add TEXT-specific properties FIRST (before common properties) |
| 52 |
$content .= $this->build_text_properties($field); |
| 53 |
|
| 54 |
// Add common properties (default, placeholder, description, separator, condition, etc.) |
| 55 |
// This includes: default, placeholder, description, label_block, show_label, |
| 56 |
// dynamic, separator, condition/conditions, selectors |
| 57 |
// Note: responsive is handled via method name change in header |
| 58 |
$content .= $this->build_common_properties($field); |
| 59 |
|
| 60 |
// Close control |
| 61 |
$content .= $this->build_control_footer(); |
| 62 |
|
| 63 |
return $content; |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* Build TEXT-specific properties |
| 68 |
* These are properties unique to TEXT control type |
| 69 |
* |
| 70 |
* @param array $field Field configuration from React UI |
| 71 |
* @return string |
| 72 |
*/ |
| 73 |
protected function build_text_properties($field) { |
| 74 |
$content = ''; |
| 75 |
|
| 76 |
// Input type (HTML5 input types: text, url, email, tel, password, search, number) |
| 77 |
// From form: Not visible in image, but supported by Elementor |
| 78 |
if (!empty($field['input_type']) && $field['input_type'] !== 'text') { |
| 79 |
$content .= $this->format_plain_string_property('input_type', $field['input_type']); |
| 80 |
} |
| 81 |
|
| 82 |
// Title (tooltip on hover) |
| 83 |
// From form: Not visible in image, but supported by Elementor |
| 84 |
if (!empty($field['title'])) { |
| 85 |
$content .= $this->format_string_property('title', $field['title']); |
| 86 |
} |
| 87 |
|
| 88 |
// Classes (custom CSS classes for control wrapper in the panel) |
| 89 |
// From form: "Control Classes" field - "Add custom classes to control wrapper in the panel" |
| 90 |
if (!empty($field['classes'])) { |
| 91 |
$content .= $this->format_plain_string_property('classes', $field['classes']); |
| 92 |
} |
| 93 |
|
| 94 |
return $content; |
| 95 |
} |
| 96 |
|
| 97 |
protected function default_label() { |
| 98 |
return 'Text'; |
| 99 |
} |
| 100 |
|
| 101 |
protected function get_type_specific_config($field) { |
| 102 |
$config = []; |
| 103 |
if (!empty($field['input_type']) && $field['input_type'] !== 'text') { |
| 104 |
$config['input_type'] = $field['input_type']; |
| 105 |
} |
| 106 |
if (!empty($field['title'])) { |
| 107 |
// translators: dynamic user-defined control title/tooltip. |
| 108 |
$config['title'] = esc_html($field['title']); |
| 109 |
} |
| 110 |
if (!empty($field['classes'])) { |
| 111 |
$config['classes'] = $field['classes']; |
| 112 |
} |
| 113 |
return $config; |
| 114 |
} |
| 115 |
} |
| 116 |
/** |
| 117 |
* FIELD MAPPING FROM REACT UI TO PHP: |
| 118 |
* ==================================== |
| 119 |
* |
| 120 |
* From Control Settings Panel [Image #1]: |
| 121 |
* |
| 122 |
* 1. Dynamic Support (toggle) → field['dynamic'] → handled by base class |
| 123 |
* Output: 'dynamic' => ['active' => true] |
| 124 |
* |
| 125 |
* 2. Separator (dropdown: None/Before/After) → field['separator'] → handled by base class |
| 126 |
* Output: 'separator' => 'none|before|after' |
| 127 |
* |
| 128 |
* 3. Conditions (condition builder) → field['condition'] → handled by base class |
| 129 |
* Example: ['other_control' => 'value'] |
| 130 |
* Output: 'condition' => ['other_control' => 'value'] |
| 131 |
* |
| 132 |
* 4. Control Classes (text input) → field['classes'] → handled in build_text_properties() |
| 133 |
* Output: 'classes' => 'custom-class-name' |
| 134 |
* |
| 135 |
* 5. Selector (text input) → field['selector'] or field['selectors'] → handled by base class |
| 136 |
* Example: {{WRAPPER}} .control-class |
| 137 |
* Output: 'selectors' => ['{{WRAPPER}} .control-class' => 'css-property'] |
| 138 |
* |
| 139 |
* Additional common fields: |
| 140 |
* - Label → field['label'] → used in control header |
| 141 |
* - Name → used for $control_key |
| 142 |
* - Description → field['description'] → handled by base class |
| 143 |
* - Placeholder → field['placeholder'] → handled by base class |
| 144 |
* - Default Value → field['default'] → handled by base class |
| 145 |
* - Show Label → field['show_label'] → handled by base class |
| 146 |
* - Label Block → field['label_block'] → handled by base class |
| 147 |
* - Responsive Control → field['responsive'] → handled by base class |
| 148 |
*/ |
| 149 |
|