public function IngredientUnitUtility::getUnitSetOptions in Recipe 8.2
Returns options for a unit set select form element.
Return value
array An array of all unit set names with unit names, keyed by set id.
File
- modules/
ingredient/ src/ Utility/ IngredientUnitUtility.php, line 115
Class
- IngredientUnitUtility
- Provides the ingredient.unit service.
Namespace
Drupal\ingredient\UtilityCode
public function getUnitSetOptions() {
$unit_sets = $this->ingredientUnitConfig
->get('unit_sets');
$set_names = [];
foreach ($unit_sets as $key => $set) {
$set_name = $set['name'];
// Append a list of the unit names in the set, in parenthesis.
$unit_names = [];
foreach ($set['units'] as $unit) {
$unit_names[] = $unit['name'];
}
if (!empty($unit_names)) {
$set_name .= ' <em>(' . implode(', ', $unit_names) . ')</em>';
}
$set_names[$key] = $set_name;
}
return $set_names;
}