You are here

public function HoverPreview::settingsSummary in Hover Preview for ImageCache 8

Returns a short summary for the current formatter settings.

If an empty result is returned, a UI can still be provided to display a settings form in case the formatter has configurable settings.

Return value

string[] A short summary of the formatter settings.

Overrides FormatterBase::settingsSummary

File

src/Plugin/Field/FieldFormatter/HoverPreview.php, line 89

Class

HoverPreview
Plugin implementation of the 'hover_preview' formatter.

Namespace

Drupal\hover_preview\Plugin\Field\FieldFormatter

Code

public function settingsSummary() {
  $summary = [];
  $settings = $this
    ->getSettings();
  $image_styles = image_style_options(FALSE);

  // Unset possible 'No defined styles' option.
  unset($image_styles['']);

  // Styles could be lost because of enabled/disabled modules that defines
  // their styles in code.
  if (isset($image_styles[$settings['image_style']])) {
    $summary[] = $this
      ->t('Image style: @style', array(
      '@style' => $image_styles[$settings['image_style']],
    ));
  }
  else {
    $summary[] = $this
      ->t('Original image');
  }
  $link_types = array(
    'content' => t('Linked to content'),
    'file' => t('Linked to file'),
  );

  // Display this setting only if image is linked.
  if (isset($link_types[$settings['image_link']])) {
    $summary[] = $link_types[$settings['image_link']];
  }

  // Add in the Hover Preview action.
  if (isset($settings['hover_preview_action']) && !empty($settings['hover_preview_action'])) {
    $summary[] = $this
      ->t('Hover preview action: @action', array(
      '@action' => $settings['hover_preview_action'],
    ));
  }
  else {
    $summary[] = $this
      ->t('Hover preview action: Preview Image');
  }

  // Display the Hover Preview image style.
  $image_styles = image_style_options(FALSE);
  if (isset($image_styles[$settings['hover_preview_style']])) {
    $summary[] = $this
      ->t('Hover preview style: @style', array(
      '@style' => $image_styles[$settings['hover_preview_style']],
    ));
  }
  else {
    $summary[] = $this
      ->t('Hover preview style: Original image');
  }
  return $summary;
}