| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Modules\AtomicWidgets\Elements\Base; |
| 4 |
|
| 5 |
class Widget_Builder { |
| 6 |
protected $widget_type; |
| 7 |
protected $settings = []; |
| 8 |
protected $is_locked = false; |
| 9 |
protected $editor_settings = []; |
| 10 |
protected $meta = []; |
| 11 |
|
| 12 |
public static function make( string $widget_type ) { |
| 13 |
return new self( $widget_type ); |
| 14 |
} |
| 15 |
|
| 16 |
private function __construct( string $widget_type ) { |
| 17 |
$this->widget_type = $widget_type; |
| 18 |
} |
| 19 |
|
| 20 |
public function settings( array $settings ) { |
| 21 |
$this->settings = $settings; |
| 22 |
return $this; |
| 23 |
} |
| 24 |
|
| 25 |
public function is_locked( $is_locked ) { |
| 26 |
$this->is_locked = $is_locked; |
| 27 |
return $this; |
| 28 |
} |
| 29 |
|
| 30 |
public function editor_settings( array $editor_settings ) { |
| 31 |
$this->editor_settings = $editor_settings; |
| 32 |
return $this; |
| 33 |
} |
| 34 |
|
| 35 |
public function meta( array $meta ) { |
| 36 |
$this->meta = $meta; |
| 37 |
return $this; |
| 38 |
} |
| 39 |
|
| 40 |
public function build() { |
| 41 |
$widget_data = [ |
| 42 |
'elType' => 'widget', |
| 43 |
'widgetType' => $this->widget_type, |
| 44 |
'settings' => $this->settings, |
| 45 |
'isLocked' => $this->is_locked, |
| 46 |
'editor_settings' => $this->editor_settings, |
| 47 |
]; |
| 48 |
|
| 49 |
if ( ! empty( $this->meta ) ) { |
| 50 |
$widget_data['meta'] = $this->meta; |
| 51 |
} |
| 52 |
|
| 53 |
return $widget_data; |
| 54 |
} |
| 55 |
} |
| 56 |
|