← All changes
|
modules/atomic-widgets/elements/base/element-builder.php
+14
-0
4.2.1
→
4.3.0-beta3
View file →
| @@ -8,8 +8,9 @@ | ||
| 8 | 8 | protected $is_locked = false; |
| 9 | 9 | protected $children = []; |
| 10 | 10 | protected $editor_settings = []; |
| 11 | 11 | protected $meta = []; |
| 12 | + protected $hydrate_default_children = false; | |
| 12 | 13 | |
| 13 | 14 | public static function make( string $element_type ) { |
| 14 | 15 | return new self( $element_type ); |
| 15 | 16 | } |
| @@ -42,8 +43,17 @@ | ||
| 42 | 43 | $this->meta = $meta; |
| 43 | 44 | return $this; |
| 44 | 45 | } |
| 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 | + | |
| 46 | 56 | public function build() { |
| 47 | 57 | $element_data = [ |
| 48 | 58 | 'elType' => $this->element_type, |
| 49 | 59 | 'settings' => $this->settings, |
| @@ -53,8 +63,12 @@ | ||
| 53 | 63 | ]; |
| 54 | 64 | |
| 55 | 65 | if ( ! empty( $this->meta ) ) { |
| 56 | 66 | $element_data['meta'] = $this->meta; |
| 67 | + } | |
| 68 | + | |
| 69 | + if ( $this->hydrate_default_children ) { | |
| 70 | + $element_data['hydrateDefaultChildren'] = true; | |
| 57 | 71 | } |
| 58 | 72 | |
| 59 | 73 | return $element_data; |
| 60 | 74 | } |