You are here

public function ImageUrlFormatter::settingsSummary in Image URL Formatter 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/ImageUrlFormatter.php, line 157

Class

ImageUrlFormatter
Plugin implementation of the 'image_url' formatter.

Namespace

Drupal\image_url_formatter\Plugin\Field\FieldFormatter

Code

public function settingsSummary() {
  $summary = [];
  switch ($this
    ->getSetting('url_type')) {
    case 2:
      $summary[] = $this
        ->t('Use relative path');
      break;
    case 1:
      $summary[] = $this
        ->t('Use absolute path');
      break;
    case 0:
      $summary[] = $this
        ->t('Use full URL');
      break;
  }
  $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.
  $image_style_setting = $this
    ->getSetting('image_style');
  if (isset($image_styles[$image_style_setting])) {
    $summary[] = $this
      ->t('URL for Image style: @style', [
      '@style' => $image_styles[$image_style_setting],
    ]);
  }
  else {
    $summary[] = $this
      ->t('Original image');
  }
  $link_types = [
    'content' => $this
      ->t('Linked to content'),
    'file' => $this
      ->t('Linked to file'),
  ];

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