Hi there,

I found a bug with the recipe module.

If you disabled the fraction display (by putting nothing on the fraction field).

You create your recipe with, for example 1.5 unit of lemon, you validate, it's ok.

If you want to edit your recipe, the quantity of lemon field in the form is empty.

I identify the origin of the bug, if you change

          $form['ingredients'][$j]['quantity'] = array(
            '#type' => 'textfield',
            '#title' => '',
            '#default_value' => preg_replace('/\⁄/', '/', recipe_ingredient_quantity_from_decimal($ingredient->quantity)),
            '#size' => 8,
            '#maxlength' => 8,
          );

By :

          $form['ingredients'][$j]['quantity'] = array(
            '#type' => 'textfield',
            '#title' => '',
            '#default_value' => preg_replace('/\⁄/', '/', $ingredient->quantity),
            '#size' => 8,
            '#maxlength' => 8,
          );

It works, so the problem is in recipe_ingredient_quantity_from_decimal(). But the function is very complex (for me) and I don't find what can cause this problem.

Any help would be appreciated :)

zmove

Comments

zmove’s picture

Status: Active » Needs review

I found a solution, I think it's not the best way to do but it works for me.

I continue to have problem to create patch (thanks windows) so I put what to do...

on recipe.module, in the recipe_ingredient_quantity_from_decimal function.

replace :

$ingredient_quantity = sprintf(variable_get('recipe_fraction_display', t('{%d} %d⁄%d')), $whole, $numerator, $denominator);

By :

if (variable_get('recipe_fraction_display', t('{%d} %d⁄%d'))) {
  $ingredient_quantity = sprintf(variable_get('recipe_fraction_display', t('{%d} %d⁄%d')), $whole, $numerator, $denominator);
}

This modification just check if the fraction variable is defined, and, apply the sprintf() if yes only (because the sprintf is not required for decimal number).

marble’s picture

Thanks, this patch seems sensible. I can't commit it right now, but will do soon unless someone else beats me to it...

marble’s picture

Status: Needs review » Fixed

Applied (with a minor mod to avoid doing the whole numerator/denominator stuff in this case). Thanks!

Anonymous’s picture

Status: Fixed » Closed (fixed)