function recipe_view in Recipe 7
Same name and namespace in other branches
- 5 recipe.module \recipe_view()
- 6 recipe.module \recipe_view()
- 7.2 recipe.module \recipe_view()
Implements hook_view().
File
- ./
recipe.module, line 705 - Contains functions for Recipe node CRUD and display.
Code
function recipe_view($node, $view_mode) {
drupal_add_css(drupal_get_path('module', 'recipe') . '/recipe.css');
if ($view_mode == 'full' && node_is_page($node)) {
$breadcrumb = array();
$breadcrumb[] = l(t('Home'), NULL);
$breadcrumb[] = l(t('Recipes'), 'recipe');
drupal_set_breadcrumb($breadcrumb);
}
// Prepare and sanitize node fields.
recipe_node_sanitize($node);
// Calculate yield and ingredient factor.
// Get custom yield or default to a factor of 1.
$node->recipe_yield = intval($node->recipe_yield);
// Factor is calculated and added into the $node variable.
$node->recipe_factor = 1;
// check post variable to see if the yield form was posted.
if ($node->recipe_yield != 0 && isset($_POST['op'])) {
if ($_POST['op'] == t('Change')) {
$node->recipe_factor = $_POST['custom_yield'] / $node->recipe_yield;
$node->recipe_yield = $_POST['custom_yield'];
$_POST = array();
}
elseif ($_POST['op'] == t('Halve')) {
$node->recipe_factor = $_POST['custom_yield'] / 2 / $node->recipe_yield;
$node->recipe_yield = $_POST['custom_yield'] / 2;
$_POST = array();
}
elseif ($_POST['op'] == t('Double')) {
$node->recipe_factor = $_POST['custom_yield'] * 2 / $node->recipe_yield;
$node->recipe_yield = $_POST['custom_yield'] * 2;
$_POST = array();
}
elseif ($_POST['op'] == t('Reset')) {
$_POST = array();
}
}
elseif (isset($node->recipe_custom_yield)) {
$node->recipe_factor = $node->recipe_custom_yield / $node->recipe_yield;
$node->recipe_yield = $node->recipe_custom_yield;
}
// If it is a teaser, you're done.
// The teaser should have a full $node object, but not the $node->content render array.
if ($view_mode == 'teaser') {
$node->content['recipe_description'] = array(
'#markup' => theme('recipe_description_summary', array(
'node' => $node,
)),
);
return $node;
}
// Begin filling the node->content array with with recipe items.
$node->content['recipe_description'] = array(
'#markup' => theme('recipe_description', array(
'node' => $node,
)),
);
$node->content['recipe_ingredients'] = array(
'#markup' => theme('recipe_ingredients', array(
'node' => $node,
)),
);
$node->content['recipe_instructions'] = array(
'#markup' => theme('recipe_instructions', array(
'node' => $node,
)),
);
// Don't show the notes box at all it there are no notes.
if ($node->recipe_notes) {
$node->content['recipe_notes'] = array(
'#markup' => theme('recipe_notes', array(
'node' => $node,
)),
);
}
if (isset($node->in_preview) && $node->in_preview == 1) {
$node->recipe_show_yield_form = FALSE;
}
$node->content['recipe_summary_box'] = array(
'#markup' => theme('recipe_summary', array(
'node' => $node,
'show_yield_form' => isset($node->recipe_show_yield_form) ? $node->recipe_show_yield_form : TRUE,
)),
);
return $node;
}