public static function LengthUnit::assertExists in Physical Fields 8
Asserts that the given unit exists.
Parameters
string $unit: The unit.
Throws
\InvalidArgumentException
Overrides UnitInterface::assertExists
2 calls to LengthUnit::assertExists()
- Dimensions::processElement in src/
Element/ Dimensions.php - Builds the physical_dimensions form element.
- LengthUnit::getBaseFactor in src/
LengthUnit.php - Gets the base factor for the given unit.
File
- src/
LengthUnit.php, line 61
Class
- LengthUnit
- Provides length units.
Namespace
Drupal\physicalCode
public static function assertExists($unit) {
$allowed_units = [
self::MILLIMETER,
self::CENTIMETER,
self::METER,
self::KILOMETER,
self::INCH,
self::FOOT,
self::NAUTICAL_MILE,
];
if (!in_array($unit, $allowed_units)) {
throw new \InvalidArgumentException(sprintf('Invalid length unit "%s" provided.', $unit));
}
}