You are here

function recipe_node_prepare in Recipe 7

Same name and namespace in other branches
  1. 5 recipe.module \recipe_node_prepare()
  2. 6 recipe.module \recipe_node_prepare()

Implements hook_node_prepare().

File

./recipe.module, line 298
Contains functions for Recipe node CRUD and display.

Code

function recipe_node_prepare($node) {

  // Populate new translation nodes with translation source values.
  if ($node->type == 'recipe' && !isset($node->nid) && isset($node->translation_source)) {
    $node->recipe_source = $node->translation_source->recipe_source;
    $node->recipe_yield = $node->translation_source->recipe_yield;
    $node->recipe_yield_unit = $node->translation_source->recipe_yield_unit;
    $node->recipe_description = $node->translation_source->recipe_description;
    $node->recipe_instructions = $node->translation_source->recipe_instructions;
    $node->recipe_notes = $node->translation_source->recipe_notes;
    $node->recipe_preptime = $node->translation_source->recipe_preptime;
    $node->recipe_cooktime = $node->translation_source->recipe_cooktime;
    $node->recipe_ingredients = $node->translation_source->recipe_ingredients;

    // Don't copy ri_id or ingredient_id because they reference the source
    // recipe node; by excluding it, it creates a new record.
    if (isset($node->recipe_ingredients['ing'])) {
      foreach ($node->recipe_ingredients['ing'] as &$ing) {
        $ing['ri_id'] = NULL;
        $ing['ingredient_id'] = NULL;
      }
    }
  }
}