You are here

protected function JuiceboxFieldFormatter::getFieldTextSources in Juicebox HTML5 Responsive Image Galleries 8.2

Same name and namespace in other branches
  1. 8.3 src/Plugin/Field/FieldFormatter/JuiceboxFieldFormatter.php \Drupal\juicebox\Plugin\Field\FieldFormatter\JuiceboxFieldFormatter::getFieldTextSources()

Utility to fetch the title and caption source options.

Source options for field-based galleries based on the properties available for this field.

Return value

array An associative array representing the key => label pairs for each title and caption source option.

2 calls to JuiceboxFieldFormatter::getFieldTextSources()
JuiceboxFieldFormatter::settingsForm in src/Plugin/Field/FieldFormatter/JuiceboxFieldFormatter.php
Returns a form to configure settings for the formatter.
JuiceboxFieldFormatter::settingsSummary in src/Plugin/Field/FieldFormatter/JuiceboxFieldFormatter.php
Returns a short summary for the current formatter settings.

File

src/Plugin/Field/FieldFormatter/JuiceboxFieldFormatter.php, line 358

Class

JuiceboxFieldFormatter
Plugin implementation of the 'juicebox' formatter.

Namespace

Drupal\juicebox\Plugin\Field\FieldFormatter

Code

protected function getFieldTextSources() {

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

  // 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 instance used
  // 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 ($this
    ->isPseudoInstance()) {
    foreach ([
      'alt_field',
      'title_field',
      'description_field',
    ] as $value) {
      $field_settings[$value] = TRUE;
    }
  }
  if (!empty($field_settings)) {

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

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

  // @todo: Add support for fieldable file entities and/or media entities.
  return $text_source_options;
}