protected static function ScssNumber::getUnitOptions in SCSS Compiler 1.0.x
Get an associative array of unit options for the supplied element.
The supplied element's "#unit_options" property will determine the result of this method using the following algorithm:
1. If "#unit_options" is an array, it will be intersected with an internal list of allowed unit options. 2. Else, if "#unit_options" is a string, the desired unit will be extracted from an internal list of allowed unit options. 3. Else, if "#unit_options" is equivalent to TRUE, all allowed unit options will be produced. 4. Else, no unit options will be produced.
Parameters
array $element: The element for which to get an associative array of unit options.
Return value
\Drupal\Core\StringTranslation\TranslatableMarkup[string] An associative array of unit option labels keyed by unit name.
1 call to ScssNumber::getUnitOptions()
- ScssNumber::processNumber in src/
Element/ ScssNumber.php - Process the element before it gets rendered in the form.
File
- src/
Element/ ScssNumber.php, line 230
Class
- ScssNumber
- A form element to represent Sass numbers with a unit.
Namespace
Drupal\compiler_scss\ElementCode
protected static function getUnitOptions(array $element) {
$allowed = self::getAllowedUnits();
$desired = $element['#unit_options'];
$result = [];
// Check whether a subset of the allowed units is desired.
if (is_array($desired)) {
$result = array_intersect_key($allowed, array_flip($desired));
}
elseif (is_string($desired) && array_key_exists($desired, $allowed)) {
$result = array_intersect_key($allowed, array_flip([
$desired,
]));
}
elseif (is_int($desired)) {
$result = self::getAllowedUnits($desired);
}
return $result;
}