• File: component-variant.php
  • Full Path: /home/slvgwrnz/public_html/wp-content/plugins/elementor/modules/components/variants/component-variant.php
  • Date Modified: 09/01/2026 8:47 AM
  • File size: 925 bytes
  • MIME-type: text/x-php
  • Charset: utf-8
<?php

namespace Elementor\Modules\Components\Variants;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

class Component_Variant {
	/** @var string */
	public $id;

	/** @var string */
	public $label;

	/**
	 * Widget entries keyed by element id. Each entry may include:
	 * - `settings.classes.add`: string[] of class ids to add on top of the base
	 * - `variant`: string id of a nested component variant to apply
	 *
	 * @var array<string, array>
	 */
	public $widgets;

	public function __construct( string $id, string $label, array $widgets ) {
		$this->id = $id;
		$this->label = $label;
		$this->widgets = $widgets;
	}

	public static function make( array $variant ): self {
		return new self(
			$variant['id'],
			$variant['label'],
			$variant['widgets'] ?? []
		);
	}

	public function to_associative_array(): array {
		return [
			'id' => $this->id,
			'label' => $this->label,
			'widgets' => $this->widgets,
		];
	}
}