* @param string|array $descriptor Path to image file, or array structure containing paths
* @param string $basePath Directory to which paths in descriptor refer
* @param array $variants
+ * @param string|null $defaultColor of the base variant
* @throws InvalidArgumentException
*/
- public function __construct( $name, $module, $descriptor, $basePath, $variants ) {
+ public function __construct( $name, $module, $descriptor, $basePath, $variants,
+ $defaultColor = null
+ ) {
$this->name = $name;
$this->module = $module;
$this->descriptor = $descriptor;
$this->basePath = $basePath;
$this->variants = $variants;
+ $this->defaultColor = $defaultColor;
// Expand shorthands:
// [ "en,de,fr" => "foo.svg" ]
if ( $variant && isset( $this->variants[$variant] ) ) {
$data = $this->variantize( $this->variants[$variant], $context );
} else {
- $data = file_get_contents( $path );
+ $defaultColor = $this->defaultColor;
+ $data = $defaultColor ?
+ $this->variantize( [ 'color' => $defaultColor ], $context ) :
+ file_get_contents( $path );
}
if ( $format === 'rasterized' ) {
protected $origin = self::ORIGIN_CORE_SITEWIDE;
protected $images = [];
+ protected $defaultColor = null;
protected $variants = [];
protected $prefix = null;
protected $selectorWithoutVariant = '.{prefix}-{name}';
$this->{$member} = $option;
break;
+ case 'defaultColor':
case 'prefix':
case 'selectorWithoutVariant':
case 'selectorWithVariant':
$this->getName(),
$fileDescriptor,
$this->localBasePath,
- $variantConfig
+ $variantConfig,
+ $this->defaultColor
);
$this->imageObjects[$skin][$image->getName()] = $image;
}