diff --git a/modules/ingredient/ingredient.module b/modules/ingredient/ingredient.module index fe4f09d..97d5c01 100644 --- a/modules/ingredient/ingredient.module +++ b/modules/ingredient/ingredient.module @@ -79,3 +79,61 @@ function ingredient_is_page(Ingredient $ingredient) { } return FALSE; } + +/** + * Converts an ingredient's quantity from decimal to fraction. + * + * @param float $ingredient_quantity + * The ingredient quantity formatted as a decimal. + * @param string $fraction_format + * A string representing the fraction format, used by sprintf(). + * @param bool $edit_mode + * Whether or not the ingredient is being edited. + * + * @return string + * The ingredient quantity formatted as a fraction. + * + * @deprecated This function was deprecated in version 8.x-2.0 and will be + * removed in version 3.0.0. Use + * \Drupal\ingredient\Utility\IngredientQuantityUtility::getQuantityFromDecimal() + * instead. + */ +function ingredient_quantity_from_decimal($ingredient_quantity, $fraction_format = '{%d} %d⁄%d', $edit_mode = FALSE) { + return \Drupal::service('ingredient.quantity')->getQuantityFromDecimal($ingredient_quantity, $fraction_format, $edit_mode); +} + +/** + * Converts an ingredient's quantity from fraction to decimal. + + * @param string $ingredient_quantity + * The ingredient quantity formatted as a fraction. + * + * @return float + * The ingredient quantity formatted as a decimal. + * + * @deprecated This function was deprecated in version 8.x-2.0 and will be + * removed in version 3.0.0. Use + * \Drupal\ingredient\Utility\IngredientQuantityUtility::getQuantityFromFraction() + * instead. + */ +function ingredient_quantity_from_fraction($ingredient_quantity) { + return \Drupal::service('ingredient.quantity')->getQuantityFromFraction($ingredient_quantity); +} + +/** + * Returns a best-guess matched unit key for a unit of measure. + * + * @param string $subject + * The unit of measure for which the function will search. + * + * @return string|false + * The unit's key from configuration or FALSE if there was no match. + * + * @deprecated This function was deprecated in version 8.x-2.0 and will be + * removed in version 3.0.0. Use + * \Drupal\ingredient\Utility\IngredientUnitFuzzymatch::getUnitFuzzymatch() + * instead. + */ +function ingredient_unit_fuzzymatch($subject) { + return \Drupal::service('ingredient.quantity')->getUnitFuzzymatch($subject); +} diff --git a/modules/ingredient/src/Utility/IngredientQuantityUtility.php b/modules/ingredient/src/Utility/IngredientQuantityUtility.php index e15779d..156fde1 100644 --- a/modules/ingredient/src/Utility/IngredientQuantityUtility.php +++ b/modules/ingredient/src/Utility/IngredientQuantityUtility.php @@ -119,7 +119,7 @@ class IngredientQuantityUtility { * @return int * The greatest common divisor of $a and $b. */ - public function getGcd($a, $b) { + protected function getGcd($a, $b) { while ($b != 0) { $remainder = $a % $b; $a = $b;