You are here

public function TwentyTwentyFormatter::settingsSummary in Glazed CMS Portfolio 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/TwentyTwentyFormatter.php, line 134

Class

TwentyTwentyFormatter
Plugin implementation of the 'twentytwenty_field_formatter' formatter.

Namespace

Drupal\cms_portfolio\Plugin\Field\FieldFormatter

Code

public function settingsSummary() {
  $summary = [];
  $image_styles = image_style_options(FALSE);
  unset($image_styles['']);
  $image_style_setting = $this
    ->getSetting('image_style');
  $cardinality = $this->fieldDefinition
    ->getFieldStorageDefinition()
    ->getCardinality();

  // Styles could be lost because of enabled/disabled modules that defines
  // their styles in code.
  if (isset($image_styles[$image_style_setting])) {
    $summary[] = $this
      ->t('Image style: @value', [
      '@value' => $image_styles[$image_style_setting],
    ]);
  }
  else {
    $summary[] = $this
      ->t('Original image');
  }
  $summary[] = $this
    ->t('Default offset: @value', [
    '@value' => $this
      ->getSetting('default_offset_pct'),
  ]);
  if ($cardinality != 2) {
    $summary[] = $this
      ->t('This image field needs to accept two images to be able to run TwentyTwenty properly, it is currently set to %value.', [
      '%value' => $cardinality > 0 ? $cardinality : 'unlimited',
    ]);
  }
  return $summary;
}