You are here

function theme_library_items_field in Library 6.2

Same name and namespace in other branches
  1. 5.2 library.theme.inc \theme_library_items_field()
  2. 6 library.theme.inc \theme_library_items_field()
  3. 7 library.theme.inc \theme_library_items_field()

Theme the items section on library entries.

1 theme call to theme_library_items_field()
library_form_alter in ./library.module
Implementation of hook_form_alter()

File

./library.theme.inc, line 78
Theming for the library module

Code

function theme_library_items_field($form) {

  // Change the button title to reflect the behavior when using JavaScript.
  drupal_add_js('if (Drupal.jsEnabled) { $(document).ready(function() { $("#edit-library-more").val("' . t('Add an Item') . '"); }); }', 'inline');
  $barcodes = variable_get('library_item_barcodes', LIBRARY_NO_BARCODES) == LIBRARY_BARCODES;
  $rows = array();
  if ($barcodes) {
    $headers[] = t('Barcode');
  }
  else {
    $headers[] = t('Copy');
  }
  $headers[] = t('Reference Only');
  $headers[] = t('Notes');
  $headers[] = t('');
  $headers[] = t('Delete');
  foreach (element_children($form) as $key) {

    // No need to print the field title every time.
    unset($form[$key]['barcode']['#title'], $form[$key]['in_circulation']['#title'], $form[$key]['notes']['#title'], $form[$key]['delete']['#title']);

    // Build the table row.
    if ($barcodes) {
      $row['data'][] = array(
        'data' => drupal_render($form[$key]['barcode']),
        'class' => 'library-barcode',
      );
    }
    else {
      $row['data'][] = array(
        'data' => $key + 1,
        'class' => 'library-copy',
      );
    }
    $row['data'][] = array(
      'data' => drupal_render($form[$key]['in_circulation']),
      'class' => 'library_circulation',
    );
    $row['data'][] = array(
      'data' => drupal_render($form[$key]['notes']),
      'class' => 'library_notes',
    );
    $row['data'][] = array(
      'data' => drupal_render($form[$key]['id']),
      'class' => 'library-id',
    );
    if ($key > 0) {
      $row['data'][] = array(
        'data' => drupal_render($form[$key]['delete']),
        'class' => 'library-delete',
      );
    }
    else {
      $row['data'][] = array();
    }

    // Add additional attributes to the row, such as a class for this row.
    if (isset($form[$key]['#attributes'])) {
      $row = array_merge($row, $form[$key]['#attributes']);
    }
    $rows[] = $row;
    $row = array();
  }
  $output = theme('table', $headers, $rows);
  $output .= drupal_render($form);
  return $output;
}