| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Modules\Components\Variants; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; |
| 7 |
} |
| 8 |
|
| 9 |
class Component_Variant { |
| 10 |
/** @var string */ |
| 11 |
public $id; |
| 12 |
|
| 13 |
/** @var string */ |
| 14 |
public $label; |
| 15 |
|
| 16 |
/** |
| 17 |
* Widget entries keyed by element id. Each entry may include: |
| 18 |
* - `settings.classes.add`: string[] of class ids to add on top of the base |
| 19 |
* - `variant`: string id of a nested component variant to apply |
| 20 |
* |
| 21 |
* @var array<string, array> |
| 22 |
*/ |
| 23 |
public $widgets; |
| 24 |
|
| 25 |
public function __construct( string $id, string $label, array $widgets ) { |
| 26 |
$this->id = $id; |
| 27 |
$this->label = $label; |
| 28 |
$this->widgets = $widgets; |
| 29 |
} |
| 30 |
|
| 31 |
public static function make( array $variant ): self { |
| 32 |
return new self( |
| 33 |
$variant['id'], |
| 34 |
$variant['label'], |
| 35 |
$variant['widgets'] ?? [] |
| 36 |
); |
| 37 |
} |
| 38 |
|
| 39 |
public function to_associative_array(): array { |
| 40 |
return [ |
| 41 |
'id' => $this->id, |
| 42 |
'label' => $this->label, |
| 43 |
'widgets' => $this->widgets, |
| 44 |
]; |
| 45 |
} |
| 46 |
} |
| 47 |
|