You are here

function _juicebox_field_text_sources in Juicebox HTML5 Responsive Image Galleries 7.2

Utility to fetch the title and caption source options for field-based galleries (addresses File Entity and Media module support).

Parameters

array $instance: An associative array containing the Drupal field instance information for a Juicebox field.

Return value

array An associative array representing the key => label pairs for each title and caption source option. Each key will match a keyed value on the file item source array when the gallery is built.

See also

_juicebox_field_get_text()

2 calls to _juicebox_field_text_sources()
juicebox_field_formatter_settings_form in includes/juicebox.field.inc
Implements hook_field_formatter_settings_form().
juicebox_field_formatter_settings_summary in includes/juicebox.field.inc
Implements hook_field_formatter_settings_summary().

File

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

Code

function _juicebox_field_text_sources($instance) {

  // Check if this is a "pseudo" instance such that the field is managed by
  // something other than the core Field API (e.g., a fake ctools instance used
  // for a panel or a view row). In this case the instance data is most likely
  // fake, and cannot tell us anything about what field options are available.
  // When this happens we pretend all relevent instance options are active.
  if (!isset($instance['id'])) {
    foreach (array(
      'alt_field',
      'title_field',
      'image_field_caption',
      'description_field',
    ) as $value) {
      $instance['settings'][$value] = TRUE;
    }
  }

  // If this is a standard image field we can use the core image "alt" and
  // "title" values.
  if (!empty($instance['settings']['alt_field'])) {
    $text_source_options['alt'] = t('Image - Alt text (processed by fallback text format)');
  }
  if (!empty($instance['settings']['title_field'])) {
    $text_source_options['title'] = t('Image - Title text (processed by fallback text format)');
  }

  // If image field caption is installed on an image field we can also use it.
  if (module_exists('image_field_caption') && !empty($instance['settings']['image_field_caption'])) {
    $text_source_options['image_field_caption'] = t('Image - Image field caption');
  }

  // If this is a standard file field we can use the core file "description"
  // value.
  if (!empty($instance['settings']['description_field'])) {
    $text_source_options['description'] = t('File - Description text (processed by fallback text format)');
  }

  // The filename should always be an available option.
  $text_source_options['filename'] = t('File - Filename (processed by fallback text format)');

  // If file entity is installed we can use fields attached to the "image"
  // file entity.
  if (module_exists('file_entity')) {

    // Get the fields that are available on the image file type.
    $image_fields = field_info_instances('file', 'image');
    foreach ($image_fields as $image_field_name => $image_field) {

      // Only text-based fields should be options.
      if (!empty($image_field['widget']['module']) && $image_field['widget']['module'] == 'text') {
        $text_source_options[$image_field_name] = t('File Entity Image - @label', array(
          '@label' => $image_field['label'],
        ));
      }
    }
  }
  return $text_source_options;
}