You are here

function _juicebox_field_get_text in Juicebox HTML5 Responsive Image Galleries 7.2

Utility to get sanitized text directly from a file field item.

This method will attempt to extract text, in a format safe for display, from the data contained within a file field item.

Parameters

array $item: An associative array representing a file field item.

string $source: The key within the $item array that contains the text that we want to extract.

Return value

string Safe text for output or an empty string if no text can be extracted.

See also

_juicebox_field_text_sources()

1 call to _juicebox_field_get_text()
juicebox_field_build_gallery in includes/juicebox.field.inc
Utility to build a Juicebox gallery based on field formatter data.

File

includes/juicebox.field.inc, line 356
Contains all hooks and related methods for the juicebox_formatter field formatter.

Code

function _juicebox_field_get_text($item, $source) {
  $text = '';
  if (!empty($item[$source])) {

    // If a field option is specified we need to try to get the value from a
    // file entity. Note that the entity can be re-created by casting the
    // field item into an object.
    if (strpos($source, 'field_') === 0) {
      $field = field_get_items('file', (object) $item, $source);
      if (!empty($field[0]['safe_value'])) {
        $text = $field[0]['safe_value'];
      }
    }
    elseif ($source == 'image_field_caption' && isset($item['image_field_caption']['value'])) {
      $format = empty($item['image_field_caption']['format']) ? filter_fallback_format() : $item['image_field_caption']['format'];
      $text = check_markup($item['image_field_caption']['value'], $format);
    }
    elseif (is_string($item[$source])) {
      $text = check_markup($item[$source]);
    }
  }
  return $text;
}