You are here

public function AutoImageStyleMediaDefault::settingsSummary in Auto image style 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 ImageFormatter::settingsSummary

File

src/Plugin/Field/FieldFormatter/AutoImageStyleMediaDefault.php, line 81

Class

AutoImageStyleMediaDefault
Plugin for responsive media image formatter.

Namespace

Drupal\auto_image_style\Plugin\Field\FieldFormatter

Code

public function settingsSummary() {
  $summary = [];
  $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_portrait_setting = $this
    ->getSetting('image_style_portrait');
  if (isset($image_styles[$image_style_portrait_setting])) {
    $summary[] = $this
      ->t('Portrait image style: @style', [
      '@style' => $image_styles[$image_style_portrait_setting],
    ]);
  }
  else {
    $summary[] = $this
      ->t('Portrait image style: Original image');
  }
  $image_style_landscape_setting = $this
    ->getSetting('image_style_landscape');
  if (isset($image_styles[$image_style_landscape_setting])) {
    $summary[] = $this
      ->t('Landscape image style: @style', [
      '@style' => $image_styles[$image_style_landscape_setting],
    ]);
  }
  else {
    $summary[] = $this
      ->t('Landscape image style: Original image');
  }
  $link_types = [
    'content' => $this
      ->t('Linked to content'),
    'file' => $this
      ->t('Linked to file'),
  ];

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