Number.php in SCSS Compiler 1.0.x
File
src/Config/Schema/Number.php
View source
<?php
namespace Drupal\compiler_scss\Config\Schema;
use Drupal\Core\Config\Schema\ArrayElement;
use Drupal\compiler_scss\Type\Number as IntermediateNumber;
class Number extends ArrayElement {
protected function getElementDefinition($key) {
$value = $this->value[$key] ?? NULL;
$definition = [];
$properties = $this
->getDataDefinition()
->getPropertyDefinitions();
if (array_key_exists($key, $properties)) {
$definition = $properties[$key]
->toArray();
}
return $this
->buildDataDefinition($definition, $value, $key);
}
public function getValue() {
$value = $this
->toArray() + [
'value' => NULL,
'unit' => NULL,
];
if (is_numeric($value['value'])) {
if (is_string($value['unit']) && strlen($value['unit']) > 0) {
return new IntermediateNumber($value['value'], $value['unit']);
}
return floatval($value['value']);
}
return NULL;
}
public function setValue($value, $notify = TRUE) {
if ($value instanceof IntermediateNumber) {
$value = [
'value' => $value
->value(),
'unit' => $value
->unit(),
];
}
elseif (is_numeric($value)) {
$value = [
'value' => $value,
];
}
parent::setValue($value, $notify);
}
}
Classes
Name |
Description |
Number |
A config schema type used to represent a Sass number. |