You are here

function theme_recipe_ingredients in Recipe 6

Same name and namespace in other branches
  1. 7 recipe.module \theme_recipe_ingredients()
1 string reference to 'theme_recipe_ingredients'
recipe_theme in ./recipe.module
Implementation of hook_theme().
1 theme call to theme_recipe_ingredients()
recipe_view in ./recipe.module
Implementation of hook_view().

File

./recipe.module, line 767
recipe.module - share recipes

Code

function theme_recipe_ingredients($node = NULL) {
  $output = '';

  // Construct the $ingredients[] array.
  if ($node->ingredients != NULL) {
    $output .= '<table>';
    foreach ($node->ingredients as $ingredient) {
      if (isset($ingredient['quantity']) && $ingredient['name']) {
        if (!$ingredient['abbreviation']) {
          $ingredient['abbreviation'] = recipe_unit_abbreviation($ingredient['unit_id']);
        }
        if ($ingredient['abbreviation'] == '') {
          $ingredient['abbreviation'] = '&nbsp;';
        }

        // In preview mode the quantity are plain text fractions and should not be multiplied.
        if ($node->build_mode != NODE_BUILD_PREVIEW) {
          if ($ingredient['quantity'] > 0) {
            $ingredient['quantity'] *= $node->factor;
          }
          else {
            $ingredient['quantity'] = '&nbsp;';
          }
          if (variable_get('recipe_fraction_display', t('{%d} %d&frasl;%d'))) {
            $ingredient['quantity'] = recipe_ingredient_quantity_from_decimal($ingredient['quantity']);
          }
        }
        if (!empty($ingredient['link'])) {
          $ingredient['name'] = l($ingredient['name'], 'node/' . $ingredient['link']);
        }
        $units = '';

        // Print the abbreviation if recipe_unit_display says too or the abbreviation is blank (ie = Unit, which we don't print).
        if (variable_get('recipe_unit_display', 0) == 0 || $ingredient['abbreviation'] == '&nbsp;') {
          $units = '<acronym ' . drupal_attributes(array(
            'title' => recipe_unit_name($ingredient['unit_id']),
          )) . '>' . $ingredient['abbreviation'] . '</acronym>';
        }
        else {
          $units = recipe_unit_name($ingredient['unit_id']);
        }
        $fullingredient = strlen($ingredient['note']) > 0 ? $ingredient['name'] . ' (' . $ingredient['note'] . ')' : $ingredient['name'];
        $output .= '<tr><td class="qty">' . $ingredient['quantity'] . '</td><td class="units">' . $units . '</td><td class="ingredient">' . $fullingredient . '</td></tr>';
      }
    }
    $output .= '</table>';
  }
  return $output;
}