You are here

function theme_ingredients_form in Recipe 7

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

Returns HTML for the ingredients subform in the recipe node edit form.

1 theme call to theme_ingredients_form()
recipe_form in ./recipe.module
Implements hook_form().

File

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

Code

function theme_ingredients_form($variables) {
  $form = $variables['form'];
  $header = array(
    '',
    t('Quantity'),
    t('Units'),
    t('Ingredient name'),
    t('Processing/Notes'),
    t('Sort Weight'),
  );
  $rows = array();
  drupal_add_tabledrag('ingredient-list', 'order', 'sibling', 'ingredient-weight');
  foreach (element_children($form) as $key) {

    // Skip the more ingredients button
    if (is_numeric($key)) {

      // Set special classes for drag and drop updating.
      $form[$key]['weight']['#attributes']['class'] = array(
        'ingredient-weight',
      );

      // Build the table row.
      $row = array(
        'data' => array(
          array(
            'class' => array(
              'choice-flag',
            ),
          ),
          drupal_render($form[$key]['ri_id']) . drupal_render($form[$key]['quantity']),
        ),
        'class' => array(
          'draggable',
        ),
      );
      $row['data'][] = drupal_render($form[$key]['unit_key']);
      $row['data'][] = drupal_render($form[$key]['name']);
      $row['data'][] = drupal_render($form[$key]['note']);
      $row['data'][] = drupal_render($form[$key]['weight']);
      $rows[] = $row;
    }
  }
  $output = theme('table', array(
    'header' => $header,
    'rows' => $rows,
    'attributes' => array(
      'id' => 'ingredient-list',
    ),
  ));
  $output .= drupal_render_children($form);
  return $output;
}