PluginProbe
Elementor Website Builder – more than just a page builder / 4.3.0-beta3
Elementor Website Builder – more than just a page builder v4.3.0-beta3
4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 All 452 releases
elementor / modules / atomic-widgets / children-dependencies / child-dependency.php

child-dependency.php in Elementor Website Builder – more than just a page builder 4.3.0-beta3, at modules/atomic-widgets/children-dependencies/child-dependency.php

72 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Elementor\Modules\AtomicWidgets\ChildrenDependencies;
4
5 use Elementor\Modules\AtomicWidgets\PropDependencies\Manager as Dependency_Manager;
6 use Elementor\Modules\AtomicWidgets\Utils\Element_Position;
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit; // Exit if accessed directly.
10 }
11
12 class Child_Dependency {
13
14 private string $child_type;
15 private ?Dependency_Manager $when = null;
16 private ?Element_Position $position = null;
17 private bool $stash = true;
18 private ?array $default_model = null;
19
20 private function __construct( string $child_type ) {
21 $this->child_type = $child_type;
22 }
23
24 public static function for( string $child_type ): self {
25 return new self( $child_type );
26 }
27
28 public function when( Dependency_Manager $when ): self {
29 $this->when = $when;
30
31 return $this;
32 }
33
34 public function position( Element_Position $position ): self {
35 $this->position = $position;
36
37 return $this;
38 }
39
40 public function stash( bool $stash = true ): self {
41 $this->stash = $stash;
42
43 return $this;
44 }
45
46 public function default_model( array $default_model ): self {
47 $this->default_model = $default_model;
48
49 return $this;
50 }
51
52 public function build(): array {
53 if ( null === $this->when ) {
54 throw new \InvalidArgumentException( 'Child_Dependency: `when` clause is required.' );
55 }
56
57 $when_config = $this->when->get();
58
59 if ( null === $when_config ) {
60 throw new \InvalidArgumentException( 'Child_Dependency: `when` clause must contain at least one term.' );
61 }
62
63 return [
64 'child_type' => $this->child_type,
65 'when' => $when_config,
66 'position' => ( $this->position ?? Element_Position::last() )->to_array(),
67 'stash' => $this->stash,
68 'default_model' => $this->default_model,
69 ];
70 }
71 }
72