| 1 |
<?php |
| 2 |
namespace MasterAddons\Inc\Admin\WidgetBuilder\Controls; |
| 3 |
|
| 4 |
use MasterAddons\Inc\Admin\WidgetBuilder\Controls\Control_Base; |
| 5 |
|
| 6 |
defined('ABSPATH') || exit; |
| 7 |
|
| 8 |
/** |
| 9 |
* MEDIA Control |
| 10 |
* Handles Elementor MEDIA control type |
| 11 |
* Media library selector for images, videos, etc. |
| 12 |
* |
| 13 |
* Supported properties: |
| 14 |
* - label: Control label |
| 15 |
* - name: Field name (used for control key) |
| 16 |
* - description: Description below field |
| 17 |
* - default: Default media array ['url' => '', 'id' => ''] |
| 18 |
* - media_type: Media type filter (image, video, audio) |
| 19 |
* |
| 20 |
* Common settings (handled by base class): |
| 21 |
* - show_label: Show/hide label |
| 22 |
* - label_block: Display label on separate line |
| 23 |
* - dynamic: Enable dynamic content support |
| 24 |
* - separator: Control separator position |
| 25 |
* - condition: Conditional display logic |
| 26 |
*/ |
| 27 |
class Media extends Control_Base { |
| 28 |
|
| 29 |
public function get_type() { |
| 30 |
return 'MEDIA'; |
| 31 |
} |
| 32 |
|
| 33 |
public function build($control_key, $field) { |
| 34 |
// Ensure proper default structure for MEDIA control |
| 35 |
if (empty($field['default']) || !is_array($field['default'])) { |
| 36 |
$field['default'] = [ |
| 37 |
'id' => '', |
| 38 |
'url' => '', |
| 39 |
]; |
| 40 |
} |
| 41 |
|
| 42 |
$label = !empty($field['label']) ? $field['label'] : 'Media'; |
| 43 |
|
| 44 |
// Check if responsive control |
| 45 |
$is_responsive = isset($field['responsive']) && $field['responsive']; |
| 46 |
|
| 47 |
// Build control header |
| 48 |
$content = $this->build_control_header($control_key, $label, 'MEDIA', $is_responsive); |
| 49 |
|
| 50 |
// Add MEDIA-specific properties FIRST |
| 51 |
$content .= $this->build_media_properties($field); |
| 52 |
|
| 53 |
// Add common properties |
| 54 |
$content .= $this->build_common_properties($field); |
| 55 |
|
| 56 |
// Close control |
| 57 |
$content .= $this->build_control_footer(); |
| 58 |
|
| 59 |
return $content; |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* Build MEDIA-specific properties |
| 64 |
* |
| 65 |
* @param array $field Field configuration |
| 66 |
* @return string |
| 67 |
*/ |
| 68 |
protected function build_media_properties($field) { |
| 69 |
$content = ''; |
| 70 |
|
| 71 |
// Media type |
| 72 |
if (!empty($field['media_type'])) { |
| 73 |
$content .= $this->format_plain_string_property('media_type', $field['media_type']); |
| 74 |
} |
| 75 |
|
| 76 |
return $content; |
| 77 |
} |
| 78 |
|
| 79 |
protected function default_label() { |
| 80 |
return 'Media'; |
| 81 |
} |
| 82 |
|
| 83 |
public function get_config($control_key, $field) { |
| 84 |
if (empty($field['default']) || !is_array($field['default'])) { |
| 85 |
$field['default'] = ['id' => '', 'url' => '']; |
| 86 |
} |
| 87 |
return parent::get_config($control_key, $field); |
| 88 |
} |
| 89 |
|
| 90 |
protected function get_type_specific_config($field) { |
| 91 |
$config = []; |
| 92 |
if (!empty($field['media_type'])) { |
| 93 |
$config['media_type'] = $field['media_type']; |
| 94 |
} |
| 95 |
return $config; |
| 96 |
} |
| 97 |
} |
| 98 |
|