You are here

function flipping_book_reference_autocomplete_value in Flipping Book 7

Value callback for a flipping_book_reference autocomplete element.

Replace the flipping_book fbid with a flipping_book title.

1 string reference to 'flipping_book_reference_autocomplete_value'
flipping_book_reference_field_widget_form in ./flipping_book_reference.module
Implements hook_field_widget_form().

File

./flipping_book_reference.module, line 439
Defines a field type for referencing one flipping_book from a node.

Code

function flipping_book_reference_autocomplete_value($element, $input, $form_state) {
  if (empty($input)) {

    // We're building the displayed 'default value': expand the raw fbid into
    // "flipping_book title [fbid:f]".
    $fbid = $element['#default_value'];
    if (!empty($fbid)) {
      $q = db_select('flipping_book', 'f');
      $q
        ->addField('f', 'title');
      $q
        ->condition('f.fbid', $fbid, '=');
      $result = $q
        ->execute();
      $value = $result
        ->fetchField();
      $value .= ' [fbid:' . $fbid . ']';
      return $value;
    }
  }
}