You are here

function theme_recipe_ingredients in Recipe 7

Same name and namespace in other branches
  1. 6 recipe.module \theme_recipe_ingredients()

Returns HTML for displaying the table of ingredients.

1 string reference to 'theme_recipe_ingredients'
recipe_theme in ./recipe.module
Implements hook_theme().
1 theme call to theme_recipe_ingredients()
recipe_view in ./recipe.module
Implements hook_view().

File

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

Code

function theme_recipe_ingredients($variables) {
  $node = $variables['node'];
  $output = "\n" . '<div class="recipe-ingredients recipe-section">';
  $output .= '<h2 class="title">' . t('Ingredients') . '</h2>';
  $unit_list = recipe_get_units();

  // Construct the $ingredients[] array.
  if ($node->recipe_ingredients['ing'] != NULL) {
    $output .= '<div class="section">';
    foreach ($node->recipe_ingredients['ing'] as $ingredient) {
      if (isset($ingredient['quantity']) && $ingredient['name']) {

        // In preview mode the quantity are plain text fractions and should not be multiplied.

        //if ( !$node->in_preview ) {
        if ($ingredient['quantity'] > 0) {
          $ingredient['quantity'] *= $node->recipe_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']);
        }
        if (isset($unit_list[$ingredient['unit_key']])) {

          // Print the singular or plural term depending on the quantity.
          $title = $ingredient['quantity'] > 1 ? $unit_list[$ingredient['unit_key']]['plural'] : $unit_list[$ingredient['unit_key']]['name'];
        }
        else {
          $title = $ingredient['unit_key'];
        }

        // Get the ingredient's unit abbreviation.
        if (!isset($ingredient['abbreviation']) && isset($unit_list[$ingredient['unit_key']])) {
          $ingredient['abbreviation'] = $unit_list[$ingredient['unit_key']]['abbreviation'];
        }
        $units = '';

        // Print the unit unless it has no abbreviation. Those units do not get
        // printed in any case.
        if (!empty($ingredient['abbreviation'])) {

          // Print the abbreviation if recipe_unit_display == 0.
          if (variable_get('recipe_unit_display', 0) == 0) {
            $units = '<abbr ' . drupal_attributes(array(
              'title' => $title,
            )) . '>' . $ingredient['abbreviation'] . '</abbr>';
          }
          else {
            $units = $title;
          }
        }
        $fullingredient = strlen($ingredient['note']) > 0 ? $ingredient['name'] . ' (' . $ingredient['note'] . ')' : $ingredient['name'];
        $output .= "\n" . '<div rel="schema:ingredient"><div typeof="schema:Ingredient"><div class="quantity-unit" property="schema:amount"> ' . $ingredient['quantity'] . ' ' . $units . '</div> <span class="ingredient-name" property="schema:name">' . $fullingredient . '</span></div></div>';
      }
    }
    $output .= '</div>';
  }
  $output .= '</div>';
  return $output;
}