You are here

public function AutoImageStyleDefault::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/AutoImageStyleDefault.php, line 59

Class

AutoImageStyleDefault
Plugin annotation @FieldFormatter( id = "auto_image_style_default", label = @Translation("Image auto orientation"), description = @Translation("Display image fields as portrait or landscape style"), field_types = { "image", } )

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');
  }
  return $summary;
}