| 1 |
<?php |
<?php |
| 2 |
// $Id: recipe.module,v 1.82 2008/04/20 19:05:12 brdwor Exp $ |
// $Id: recipe.module,v 1.83 2009/06/26 11:53:01 marble Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 112 |
} |
} |
| 113 |
|
|
| 114 |
/** |
/** |
| 115 |
* Implementation of hook_form(). |
* Implementation of hook_form(). |
| 116 |
*/ |
*/ |
| 117 |
function recipe_form(&$node) { |
function recipe_form(&$node,$form_state) { |
| 118 |
// drupal 4.7 requires the title field to be defined by the custom node's module |
// drupal 4.7 requires the title field to be defined by the custom node's module |
| 119 |
$form['title'] = array('#type' => 'textfield', '#title' => t('Title'), |
$form['title'] = array('#type' => 'textfield', '#title' => t('Title'), |
| 120 |
'#size' => 60, '#maxlength' => 128, '#required' => TRUE, |
'#size' => 60, '#maxlength' => 128, '#required' => TRUE, |
| 179 |
$num_ingredients = $id+1; |
$num_ingredients = $id+1; |
| 180 |
if ($id == 0) { |
if ($id == 0) { |
| 181 |
$j = '0'; |
$j = '0'; |
| 182 |
} |
} else { |
|
else { |
|
| 183 |
$j = $id; |
$j = $id; |
| 184 |
} |
} |
| 185 |
if ($ingredient->name && isset($ingredient->quantity)) { |
|
| 186 |
|
// For preview, node->ingredients is an array, for actual display, it's an object |
| 187 |
|
$name = ''; |
| 188 |
|
$unit_id = ''; |
| 189 |
|
$abbreviation = ''; |
| 190 |
|
$quantity = 0; |
| 191 |
|
if (is_array($ingredient)) { |
| 192 |
|
$name = $ingredient['name']; |
| 193 |
|
$unit_id = $ingredient['unit_id']; |
| 194 |
|
$abbreviation = $ingredient['abbreviation']; |
| 195 |
|
$quantity = $ingredient['quantity']; |
| 196 |
|
} else { |
| 197 |
|
$name = $ingredient->name; |
| 198 |
|
$unit_id = $ingredient->unit_id; |
| 199 |
|
$abbreviation = $ingredient->abbreviation; |
| 200 |
|
$quantity = $ingredient->quantity; |
| 201 |
|
} |
| 202 |
|
|
| 203 |
|
if ($name && isset($quantity)) { |
| 204 |
// When can the following statement be true? |
// When can the following statement be true? |
| 205 |
if (!$ingredient) { |
if (!$ingredient) { |
| 206 |
drupal_set_message(t('Recipe Module: An error has occured. Please report this error to the system administrator.'), 'error'); |
drupal_set_message(t('Recipe Module: An error has occured. Please report this error to the system administrator.'), 'error'); |
| 207 |
$ingredient->quantity = ''; |
if (is_array($ingredient)) { |
| 208 |
$ingredient->unit_id = 21; |
$ingredient['quantity'] = ''; |
| 209 |
$ingredient->name = ''; |
$ingredient['unit_id'] = 21; |
| 210 |
|
$ingredient['name'] = ''; |
| 211 |
|
} else { |
| 212 |
|
$ingredient->quantity = ''; |
| 213 |
|
$ingredient->unit_id = 21; |
| 214 |
|
$ingredient->name = ''; |
| 215 |
|
} |
| 216 |
} |
} |
| 217 |
if ($system == 'complex') { |
if ($system == 'complex') { |
| 218 |
$form['ingredients'][$j]['open_tags'] = array( |
$form['ingredients'][$j]['open_tags'] = array( |
| 221 |
$form['ingredients'][$j]['quantity'] = array( |
$form['ingredients'][$j]['quantity'] = array( |
| 222 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 223 |
'#title' => '', |
'#title' => '', |
| 224 |
'#default_value' => preg_replace('/\⁄/', '/', recipe_ingredient_quantity_from_decimal($ingredient->quantity)), |
'#default_value' => preg_replace('/\⁄/', '/', recipe_ingredient_quantity_from_decimal($quantity)), |
| 225 |
'#size' => 8, |
'#size' => 8, |
| 226 |
'#maxlength' => 8, |
'#maxlength' => 8, |
| 227 |
); |
); |
| 231 |
$form['ingredients'][$j]['unit_id'] = array( |
$form['ingredients'][$j]['unit_id'] = array( |
| 232 |
'#type' => 'select', |
'#type' => 'select', |
| 233 |
'#title' => '', |
'#title' => '', |
| 234 |
'#default_value' => $ingredient->unit_id, |
'#default_value' => $unit_id, |
| 235 |
'#options' => recipe_unit_options(), |
'#options' => recipe_unit_options(), |
| 236 |
); |
); |
| 237 |
$form['ingredients'][$j]['mid2_tags'] = array( |
$form['ingredients'][$j]['mid2_tags'] = array( |
| 240 |
$form['ingredients'][$j]['name'] = array( |
$form['ingredients'][$j]['name'] = array( |
| 241 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 242 |
'#title' => '', |
'#title' => '', |
| 243 |
'#default_value' => $ingredient->name, |
'#default_value' => $name, |
| 244 |
'#size' => 64, |
'#size' => 64, |
| 245 |
'#maxlength' => 128, |
'#maxlength' => 128, |
| 246 |
'#autocomplete_path' => $callback, |
'#autocomplete_path' => $callback, |
| 250 |
); |
); |
| 251 |
} |
} |
| 252 |
else { |
else { |
| 253 |
if ($ingredient->name) { |
if ($name) { |
| 254 |
if ($ingredient->quantity == 0) { |
if ($quantity == 0) { |
| 255 |
$ingredient->quantity = ''; |
$quantity = ''; |
| 256 |
} |
} |
| 257 |
else { |
else { |
| 258 |
$ingredient->quantity .= ' '; |
$quantity .= ' '; |
| 259 |
} |
} |
| 260 |
if ($ingredient->abbreviation != '') { |
if ($abbreviation != '') { |
| 261 |
$ingredient->abbreviation .= ' '; |
$abbreviation .= ' '; |
| 262 |
} |
} |
| 263 |
$ingredient->name = $ingredient->quantity . $ingredient->abbreviation . $ingredient->name; |
$name = $quantity . $abbreviation . $name; |
| 264 |
} |
} |
| 265 |
$form['ingredients'][$j]['open_tags'] = array( |
$form['ingredients'][$j]['open_tags'] = array( |
| 266 |
'#value' => '<tr><th>', |
'#value' => '<tr><th>', |
| 269 |
$form['ingredients'][$j]['name'] = array( |
$form['ingredients'][$j]['name'] = array( |
| 270 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 271 |
'#title' => '', |
'#title' => '', |
| 272 |
'#default_value' => $ingredient->name, |
'#default_value' => $name, |
| 273 |
'#size' => 64, |
'#size' => 64, |
| 274 |
'#maxlength' => 128, |
'#maxlength' => 128, |
| 275 |
'#autocomplete_path' => $callback, |
'#autocomplete_path' => $callback, |