You are here

public static function MeasurementType::getUnitClass in Physical Fields 8

Gets the unit class for the given measurement type.

Parameters

string $type: The measurement type.

Return value

string The fully qualified class name.

5 calls to MeasurementType::getUnitClass()
Measurement::convert in src/Measurement.php
Converts the current measurement to a new unit.
Measurement::processElement in src/Element/Measurement.php
Builds the physical_measurement form element.
Measurement::__construct in src/Measurement.php
Constructs a new Measurement object.
MeasurementDefaultFormatter::viewElements in src/Plugin/Field/FieldFormatter/MeasurementDefaultFormatter.php
Builds a renderable array for a field value.
MeasurementDefaultWidget::getUnitClass in src/Plugin/Field/FieldWidget/MeasurementDefaultWidget.php
Gets the unit class for the current field.

File

src/MeasurementType.php, line 63

Class

MeasurementType
Provides measurement types.

Namespace

Drupal\physical

Code

public static function getUnitClass($type) {
  self::assertExists($type);
  $classes = [
    self::AREA => AreaUnit::class,
    self::LENGTH => LengthUnit::class,
    self::TEMPERATURE => TemperatureUnit::class,
    self::VOLUME => VolumeUnit::class,
    self::WEIGHT => WeightUnit::class,
  ];
  return $classes[$type];
}