You are here

function _library_item_form in Library 7

Same name and namespace in other branches
  1. 5.2 library.module \_library_item_form()
  2. 6.2 library.module \_library_item_form()
  3. 6 library.module \_library_item_form()

Sub-form for an instance of a library item on node create/edit.

Parameters

int $delta: Delta of the item (usage unknown).

array $item: The item itself.

Return value

array The form the item.

1 call to _library_item_form()
library_form_alter in ./library.module
Implements hook_form_alter().

File

./library.module, line 288

Code

function _library_item_form($delta, $item = array()) {
  $form = array(
    '#tree' => TRUE,
  );
  $form['id'] = array(
    '#type' => 'hidden',
    '#value' => isset($item['id']) ? $item['id'] : '',
    '#parents' => array(
      'library_items',
      $delta,
      'id',
    ),
  );
  if (variable_get('library_item_barcodes', LIBRARY_NO_BARCODES) == LIBRARY_BARCODES) {
    $form['barcode'] = array(
      '#type' => 'textfield',
      '#title' => t('Barcode'),
      '#default_value' => isset($item['barcode']) ? $item['barcode'] : '',
      '#required' => TRUE,
      '#parents' => array(
        'library_items',
        $delta,
        'barcode',
      ),
    );
  }
  $form['in_circulation'] = array(
    '#type' => 'checkbox',
    '#title' => t('Reference Only'),
    '#default_value' => isset($item['in_circulation']) ? $item['in_circulation'] : LIBRARY_CIRCULATION,
    '#return_value' => LIBRARY_REFERENCE_ONLY,
    '#parents' => array(
      'library_items',
      $delta,
      'in_circulation',
    ),
  );
  $form['notes'] = array(
    '#type' => 'textfield',
    '#title' => t('Notes'),
    '#size' => 20,
    '#maxlength' => 128,
    '#default_value' => isset($item['notes']) ? $item['notes'] : '',
    '#parents' => array(
      'library_items',
      $delta,
      'notes',
    ),
  );
  if ($delta > 0) {
    if (!isset($item['id']) || isset($item['id']) && $item['library_status'] == LIBRARY_ITEM_AVAILABLE) {

      // Only allow deletes of items that are either new or checked in.
      $form['delete'] = array(
        '#type' => 'checkbox',
        '#title' => t('Delete'),
        '#default_value' => 0,
        '#return_value' => 1,
        '#parents' => array(
          'library_items',
          $delta,
          'delete',
        ),
      );
    }
  }
  if (isset($item['library_status']) && $item['library_status'] == LIBRARY_ITEM_UNAVAILABLE) {
    $form['in_circulation']['#disabled'] = TRUE;
  }
  return $form;
}