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