You are here

public function ColorboxFormatter::settingsSummary in Colorbox 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/ColorboxFormatter.php, line 290

Class

ColorboxFormatter
Plugin implementation of the 'colorbox' formatter.

Namespace

Drupal\colorbox\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.
  if (isset($image_styles[$this
    ->getSetting('colorbox_node_style')])) {
    $summary[] = $this
      ->t('Content image style: @style', [
      '@style' => $image_styles[$this
        ->getSetting('colorbox_node_style')],
    ]);
  }
  elseif ($this
    ->getSetting('colorbox_node_style') == 'hide') {
    $summary[] = $this
      ->t('Content image style: Hide');
  }
  else {
    $summary[] = $this
      ->t('Content image style: Original image');
  }
  if (isset($image_styles[$this
    ->getSetting('colorbox_node_style_first')])) {
    $summary[] = $this
      ->t('Content image style of first image: @style', [
      '@style' => $image_styles[$this
        ->getSetting('colorbox_node_style_first')],
    ]);
  }
  if (isset($image_styles[$this
    ->getSetting('colorbox_image_style')])) {
    $summary[] = $this
      ->t('Colorbox image style: @style', [
      '@style' => $image_styles[$this
        ->getSetting('colorbox_image_style')],
    ]);
  }
  else {
    $summary[] = $this
      ->t('Colorbox image style: Original image');
  }
  $gallery = [
    'post' => $this
      ->t('Per post gallery'),
    'page' => $this
      ->t('Per page gallery'),
    'field_post' => $this
      ->t('Per field in post gallery'),
    'field_page' => $this
      ->t('Per field in page gallery'),
    'custom' => $this
      ->t('Custom (with tokens)'),
    'none' => $this
      ->t('No gallery'),
  ];
  if ($this
    ->getSetting('colorbox_gallery')) {
    $summary[] = $this
      ->t('Colorbox gallery type: @type', [
      '@type' => $gallery[$this
        ->getSetting('colorbox_gallery')],
    ]) . ($this
      ->getSetting('colorbox_gallery') == 'custom' ? ' (' . $this
      ->getSetting('colorbox_gallery_custom') . ')' : '');
  }
  $caption = [
    'auto' => $this
      ->t('Automatic'),
    'title' => $this
      ->t('Title text'),
    'alt' => $this
      ->t('Alt text'),
    'entity_title' => $this
      ->t('Content title'),
    'custom' => $this
      ->t('Custom (with tokens)'),
    'none' => $this
      ->t('None'),
  ];
  if ($this
    ->getSetting('colorbox_caption')) {
    $summary[] = $this
      ->t('Colorbox caption: @type', [
      '@type' => $caption[$this
        ->getSetting('colorbox_caption')],
    ]);
  }
  return $summary;
}