← All changes
|
modules/atomic-widgets/elements/base/element-builder.php
+24
-0
4.1.0-dev2
→
4.3.0-beta3
View file →
| @@ -7,8 +7,10 @@ | ||
| 7 | 7 | protected $settings = []; |
| 8 | 8 | protected $is_locked = false; |
| 9 | 9 | protected $children = []; |
| 10 | 10 | protected $editor_settings = []; |
| 11 | + protected $meta = []; | |
| 12 | + protected $hydrate_default_children = false; | |
| 11 | 13 | |
| 12 | 14 | public static function make( string $element_type ) { |
| 13 | 15 | return new self( $element_type ); |
| 14 | 16 | } |
| @@ -36,8 +38,22 @@ | ||
| 36 | 38 | $this->children = $children; |
| 37 | 39 | return $this; |
| 38 | 40 | } |
| 39 | 41 | |
| 42 | + public function meta( array $meta ) { | |
| 43 | + $this->meta = $meta; | |
| 44 | + return $this; | |
| 45 | + } | |
| 46 | + | |
| 47 | + /** | |
| 48 | + * Marks this payload to seed its default children client-side (via | |
| 49 | + * `AtomicElementBaseModel::onElementCreate()`) once inserted into the editor. | |
| 50 | + */ | |
| 51 | + public function hydrate_default_children( bool $hydrate = true ) { | |
| 52 | + $this->hydrate_default_children = $hydrate; | |
| 53 | + return $this; | |
| 54 | + } | |
| 55 | + | |
| 40 | 56 | public function build() { |
| 41 | 57 | $element_data = [ |
| 42 | 58 | 'elType' => $this->element_type, |
| 43 | 59 | 'settings' => $this->settings, |
| @@ -44,8 +60,16 @@ | ||
| 44 | 60 | 'isLocked' => $this->is_locked, |
| 45 | 61 | 'editor_settings' => $this->editor_settings, |
| 46 | 62 | 'elements' => $this->children, |
| 47 | 63 | ]; |
| 64 | + | |
| 65 | + if ( ! empty( $this->meta ) ) { | |
| 66 | + $element_data['meta'] = $this->meta; | |
| 67 | + } | |
| 68 | + | |
| 69 | + if ( $this->hydrate_default_children ) { | |
| 70 | + $element_data['hydrateDefaultChildren'] = true; | |
| 71 | + } | |
| 48 | 72 | |
| 49 | 73 | return $element_data; |
| 50 | 74 | } |
| 51 | 75 | } |