Number.php in SCSS Compiler 1.0.x
File
src/Plugin/DataType/Number.php
View source
<?php
namespace Drupal\compiler_scss\Plugin\DataType;
use Drupal\Core\TypedData\Plugin\DataType\Map;
use Drupal\compiler_scss\Type\Number as IntermediateNumber;
class Number extends Map {
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 data type used to represent a Sass number. |