Yield Field Not Reflecting
| Project: | Recipe |
| Version: | 6.x-1.x-dev |
| Component: | User interface |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
| Issue tags: | duplicate entry |
Jump to:
I was wondering if anyone knows why the "yield" field comes up blank after entering information?
I checked my "MySql" table and everything is present...in the "yield" field! The form allows for the entry but doesn't display when rendered. Also, I noticed that the "Change", "Halve" & "Double" buttons work, if you know what the yield is in the first place. Not sure if this is the correct function but, when I do enter a number in the yield box and click on one of the buttons, the recipe changes as it should but the yield box goes blank again! So, the information is there, and it can be manipulated, but is not rendering!
Don't know if this helps, but I went to the source page and checked out the code:
<div class="content"><div class="recipe-summary"><div class="box">
<h2>Summary</h2>
<div class="content"><table><tr><th>Yield</th><td><form action="/node/616" accept-charset="UTF-8" method="post" id="recipe-custom-yield-form">
<div><fieldset><div class="form-item" id="edit-custom-yield-wrapper">
<input type="text" maxlength="4" name="custom_yield" id="edit-custom-yield" size="2" value="" class="form-text" />
</div>
<input type="submit" name="op" id="edit-submit" value="Change" class="form-submit" />
<input type="submit" name="op" id="edit-halve" value="Halve" class="form-submit" />
<input type="submit" name="op" id="edit-double" value="Double" class="form-submit" />
</fieldset>
<input type="hidden" name="form_build_id" id="form-0cdbc2f6e6f55f545b4b97d6eaf363ff" value="form-0cdbc2f6e6f55f545b4b97d6eaf363ff" />
<input type="hidden" name="form_token" id="edit-recipe-custom-yield-form-form-token" value="25389829b8031e1eaefe11489cd19710" />
<input type="hidden" name="form_id" id="edit-recipe-custom-yield-form" value="recipe_custom_yield_form" />It appears, at least to me, that the yield is being called for from the DB!
System Info:
Drupal 6.2
Recipe Module 6.x-1.0-beta1
MySQL DB 5.0.45
Checked on Firefox v2, IE v6
Otherwise, I really like this module...it works great!
Thanks

#1
I have also just noticed the same problem with version 6.0 beta. :(
Also if one wants to edit a recipe, the form ingredients' form comes empty, unlike in D5 where it's pre-populated with existing values.
Has anyone figured out how to solve this?
v.5 functions well and I have it on a D5 site for about 1 year. I also LOVE it.
Meanwhile, I was using the Node Images module to add multiple images to/within a recipe, but there's no sign of a D6 version.
Can anyone anyone suggest any equivalent or better alternative for D6?
Unless I use the "attachment" method of the image module wrongly, I preferred the above as the images + recipe are on the same page.
#2
Well, as mentioned here http://drupal.org/node/250117 the problem of the ingredients missing on submission or during editing comes up if one "previews".
After reading that bug report, I edited a recipe whose ingredients had been ignored and they appeared - also in the table during subsequent further editing.
#3
Hello,
I love this module, I do not know if this can help but if you click on "Printer-friendly version" the yield appears correctly.
Thanks !
#4
I confirm what cicciobombolo said in #3, it indeed shows the Yield on "Printer-friendly version" page (Export HTML).
Also i add that Yield appears well on these pages:
-"Preview" (but w/no ingredients)
-"Edit"
-"Export to RecipeML"
-"Printer-friendly version" (Export HTML)
Appears blank:
-On "View" page
I decided to write the Yield (how many persons) under "Description" and under "Notes" a simple hint to my visitors wishing to use the Yield fieldset for calculations. I know this is not the basic use of the module but, at least it HELPs!
Untill someone find a solution for it!!!
P.S.: I've been chkng "recipe.module" but haven't found anything yet. Also chkd difs between version 5.
#5
Ok, as lionheart8 said in #1, i confirm that version "recipe-5.x-1.0.tar.gz" for Drupal 5.x running on my server:
-MySQL 5.0.51b
-PHP 5.2.6
-Apache/2.2.8 (Unix)
is working fine!!!
Information:
1- Indeed "Yield" shows under pages:
-Edit
-Preview
-View
-Export to RecipeML
-Printer-friendly version (Export HTML)
2-But ingredients DOES not show under "Preview"
Right?
#6
On 2008-Sep-19, today, we get a new dev version that still:
-Not showing Yield field
-Not correcting the issue with the "Preview" page not showing ingredients
#7
Here's a fix
I was tracing the code and found the issue for 6.x-1.0-beta1. The first agrument of recipe_custom_yield_form() is an empty form state collection. When calling drupal_get_form('recipe_custom_yield_form', $node), $node actually comes in as the second argument of recipe_custom_yield_form().
Not sure if this is 'proper' or not, but I added a second field to the form and set the yield default value accordingly.
To fix, just replace the original function with this one: (i only changed 2 lines, and added 1 more)
function recipe_custom_yield_form($form_state=array(), $node=null) {
$yield = $node?$node->yield:null;
$form['custom_yield_container'] = array(
'#type' => 'fieldset',
'#collapsible' => FALSE,
'#collapsed' => FALSE
);
$form['custom_yield_container']['custom_yield'] = array(
'#type' => 'textfield',
'#default_value' => $yield,
'#size' => 2,
'#maxlength' => 4
);
$form['custom_yield_container']['submit'] = array(
'#type' => 'submit',
'#value' => t('Change')
);
$form['custom_yield_container']['halve'] = array(
'#type' => 'submit',
'#value' => t('Halve')
);
$form['custom_yield_container']['double'] = array(
'#type' => 'submit',
'#value' => t('Double')
);
return $form;
}
Love the module by the way, great work.
#8
Could there be the amount in a drop down box. Such as units, dozen, and such...
#9
THANK YOU! Works like a charm!
#10
#7 Fixed this issue for me. Suggest pushing to next release. Unfortunately I have not mastered patching yet, or I would offer one up! I have changed this to a bug with Critical status because the recipe is worthless without this field output on the recipe page.
#11
Hi
For some reason I dont quite get, I replaced that whole function in recipe.module 6 Beta1 with the one shown above but the problem of unpopulated ingredient fields persists.
What could I be doing wrong?
I have had to write an explanation to users, telling them to reckon with refilling ingredients whenever they edit & only do so WHEN reviewing & not before. Quite cumbersome if one has many ingredients. :(
The D 5 version on another site has never had this.
#12
See issue http://drupal.org/node/263432
The problem is that in Drupal 6 the function API has changed, function recipe_custom_yield_form needs an extra parameter '$form_id' which is mandatory (but unused here)
Adding the parameter fixed the issue for me
#13
Thanks for pointing me to this, I used that solution and for the first time since I upgraded to Drupal 6, I was able to see YIELDS!!!!
I still have another problem that has persisted, though:
Do you have anything like this or if you solved it, what did you do?
The combination of the 2 had made me lose enthusiasm for submitting or editing recipes & encouraging site guests to do the same.
#14
I didn't try the preview button yet, but when I did I noticed the issue. It turns out to be an issue in function recipe_form: for preview the 'ingredients' are an array, while for submit they are an object
A fix for the code is below (still needs some cleanup):
/**
* Implementation of hook_form().
*/
function recipe_form(&$node,$form_state) {
// drupal 4.7 requires the title field to be defined by the custom node's module
$form['title'] = array('#type' => 'textfield', '#title' => t('Title'),
'#size' => 60, '#maxlength' => 128, '#required' => TRUE,
'#default_value' => $node->title);
// Now we define the form elements specific to our node type.
$form['body'] = array(
'#type' => 'textarea',
'#title' => t('Description'),
'#default_value' => $node->body,
'#cols' => 60,
'#rows' => 2,
'#description' => t('A short description or "teaser" for the recipe.'),
'#required' => TRUE,
);
$form['yield'] = array(
'#type' => 'textfield',
'#title' => t('Yield'),
'#default_value' => $node->yield,
'#size' => 10,
'#maxlength' => 10,
'#description' => t('The number of servings the recipe will make.'),
'#attributes' => NULL,
'#required' => TRUE,
);
$form['preptime'] = array(
'#type' => 'select',
'#title' => t("Preparation time"),
'#default_value' => $node->preptime,
'#options' => array(5 => t('5 minutes'), 10 => t('10 minutes'), 15 => t('15 minutes'), 20 => t('20 minutes'), 30 => t('30 minutes'), 45 => t('45 minutes'), 60 => t('1 hour'), 90 => t('1 1/2 hours'), 120 => t('2 hours'), 150 => t('2 1/2 hours'), 180 => t('3 hours'), 210 => t('3 1/2 hours'), 240 => t('4 hours'), 300 => t('5 hours'), 360 => t('6 hours')),
'#description' => t("How long does this recipe take to prepare (i.e. elapsed time)"),
);
$form["source"] = array(
'#type' => 'textfield',
'#title' => t("Source"),
'#default_value' => $node->source,
'#size' => 60,
'#maxlength' => 127,
'#description' => t("Optional. Does anyone else deserve credit for this recipe?"),
);
// Table of existing ingredients
$form['ingredients']['#tree'] = TRUE;
$system = variable_get('recipe_ingredient_system', 'complex');
if ($system == 'complex') {
$form['ingredients']['headings'] = array(
'#value' => '<div><table ><thead><tr><th>'. t('Quantity') .'</th><th>'.
t('Units') .'</th><th>'. t('Ingredient Name') .
'</th></tr></thead>'."\n".'<tbody>',
);
}
else {
$form['ingredients']['headings'] = array(
'#value' => '<div><table ><thead><tr><th>'. t('Ingredients') .'</th></tr></thead>'."\n".'<tbody>',
);
}
$rows = array();
$callback = 'recipe/ingredient/autocomplete';
$num_ingredients = 0;
if ($node->ingredients) {
foreach ($node->ingredients as $id => $ingredient) {
$num_ingredients = $id+1;
if ($id == 0) {
$j = '0';
} else {
$j = $id;
}
// For preview, node->ingredients is an array, for actual display, it's an object
$name = '';
$unit_id = '';
$abbreviation = '';
$quantity = 0;
if (is_array($ingredient)) {
$name = $ingredient['name'];
$unit_id = $ingredient['unit_id'];
$abbreviation = $ingredient['abbreviation'];
$quantity = $ingredient['quantity'];
} else {
$name = $ingredient->name;
$unit_id = $ingredient->unit_id;
$abbreviation = $ingredient->abbreviation;
$quantity = $ingredient->quantity;
}
if ($name && isset($quantity)) {
// When can the following statement be true?
if (!$ingredient) {
drupal_set_message(t('Recipe Module: An error has occured. Please report this error to the system administrator.'), 'error');
// TODO Fix in case it is an array!
$ingredient->quantity = '';
$ingredient->unit_id = 21;
$ingredient->name = '';
}
if ($system == 'complex') {
$form['ingredients'][$j]['open_tags'] = array(
'#value' => '<tr><th>',
);
$form['ingredients'][$j]['quantity'] = array(
'#type' => 'textfield',
'#title' => '',
'#default_value' => preg_replace('/\⁄/', '/', recipe_ingredient_quantity_from_decimal($quantity)),
'#size' => 8,
'#maxlength' => 8,
);
$form['ingredients'][$j]['mid1_tags'] = array(
'#value' => '</th><th>',
);
$form['ingredients'][$j]['unit_id'] = array(
'#type' => 'select',
'#title' => '',
'#default_value' => $unit_id,
'#options' => recipe_unit_options(),
);
$form['ingredients'][$j]['mid2_tags'] = array(
'#value' => '</th><th>',
);
$form['ingredients'][$j]['name'] = array(
'#type' => 'textfield',
'#title' => '',
'#default_value' => $name,
'#size' => 64,
'#maxlength' => 128,
'#autocomplete_path' => $callback,
);
$form['ingredients'][$j]['close_tags'] = array(
'#value' => '</th></tr>',
);
}
else {
if ($name) {
if ($quantity == 0) {
$quantity = '';
}
else {
$quantity .= ' ';
}
if ($abbreviation != '') {
$abbreviation .= ' ';
}
$name = $quantity . $abbreviation . $name;
}
$form['ingredients'][$j]['open_tags'] = array(
'#value' => '<tr><th>',
'#tree' => TRUE,
);
$form['ingredients'][$j]['name'] = array(
'#type' => 'textfield',
'#title' => '',
'#default_value' => $name,
'#size' => 64,
'#maxlength' => 128,
'#autocomplete_path' => $callback,
);
$form['ingredients'][$j]['close_tags'] = array(
'#value' => '</th></tr>',
);
} // else
} // if ($ingredient->name && isset($ingredient->quantity))
} // foreach ($node->ingredients as $id => $ingredient)
} // if ($node->ingredients)
// Add ten more spots for ingredients than are already used
for ($i = $num_ingredients; $i < $num_ingredients+10; $i++) {
if ($i == 0) {
$j = '0';
}
else {
$j = $i;
}
if ($system == 'complex') {
$form['ingredients'][$j]['open_tags'] = array(
'#value' => '<tr><th>',
);
$form['ingredients'][$j]['quantity'] = array(
'#type' => 'textfield',
'#title' => '',
'#size' => 8,
'#maxlength' => 8,
);
$form['ingredients'][$j]['mid1_tags'] = array(
'#value' => '</th><th>',
);
$form['ingredients'][$j]['unit_id'] = array(
'#type' => 'select',
'#title' => '',
'#options' => recipe_unit_options(),
'#default_value' => 2,
);
$form['ingredients'][$j]['mid2_tags'] = array(
'#value' => '</th><th>',
);
$form['ingredients'][$j]['name'] = array(
'#type' => 'textfield',
'#title' => '',
'#size' => 64,
'#maxlength' => 128,
'#autocomplete_path' => $callback,
);
$form['ingredients'][$j]['close_tags'] = array(
'#value' => '</th></tr>',
);
}
else {
$form['ingredients'][$j]['open_tags'] = array(
'#value' => '<tr><th>',
);
$form['ingredients'][$j]['name'] = array(
'#type' => 'textfield',
'#title' => '',
'#size' => 64,
'#maxlength' => 128,
'#autocomplete_path' => $callback,
);
$form['ingredients'][$j]['close_tags'] = array(
'#value' => '</th></tr>',
);
}
}
$form['ingredients']['end'] = array(
'#value' => '</tbody>'."\n".'</table></div>'."\n",
);
$form['instructions'] = array(
'#type' => 'textarea',
'#title' => t('Instructions'),
'#default_value' => $node->instructions,
'#cols' => 60,
'#rows' => 10,
'#description' => t('Step by step instructions on how to prepare and cook the recipe.'),
);
$form['notes'] = array(
'#type' => 'textarea',
'#title' => t("Additional Notes"),
'#default_value' => $node->notes,
'#cols' => 60,
'#rows' => 5,
'#description' => t("Optional. Describe a great dining experience relating to this recipe, or note which wine or other dishes complement this recipe"),
);
$form['filter'] = filter_form($node->format);
return $form;
}
#15
That seems to do the trick!!!!!
In a preliminary test, I edited a recipe & on "previewing" the ingredients did not vanish, needing filling them in anew.
This has been very annoying & now after almost a year I dont regret upgrading to D6 - as far as the recipe module is concerned, which apparently is a key part of my community site.
So I have to go to the recipe section & edit the long submission instructions' section which told users how to deal with the 2 problems, one mentioned here & the other of the not appearing "yield" which has also been solved.
Thanks again - but in case there's some hiccup somewhere, I think I know where to turn - especially since you said the code "still needs some cleanup". For now, it looks clean. ;)
Regards
#16
Thanks everyone. I've committed the fix as well as the patch for the ingredients issue from jbemmel.
#17
Automatically closed -- issue fixed for 2 weeks with no activity.