You are here

public function TwentyTwentyFieldFormatter::settingsSummary in ZURB TwentyTwenty 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/Field/FieldFormatter/TwentyTwentyFieldFormatter.php \Drupal\zurb_twentytwenty\Plugin\Field\FieldFormatter\TwentyTwentyFieldFormatter::settingsSummary()

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/TwentyTwentyFieldFormatter.php, line 191
Contains Drupal\zurb_twentytwenty\Plugin\Field\FieldFormatter\TwentyTwentyFieldFormatter.

Class

TwentyTwentyFieldFormatter
Plugin implementation of the 'twentytwenty_field_formatter' formatter.

Namespace

Drupal\zurb_twentytwenty\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', array(
      '@value' => $image_styles[$image_style_setting],
    ));
  }
  else {
    $summary[] = $this
      ->t('Original image');
  }
  $booleanToString = [
    'false',
    'true',
  ];
  $summary[] = $this
    ->t('Default offset: @value', array(
    '@value' => $this
      ->getSetting('default_offset_pct'),
  ));
  $summary[] = $this
    ->t('Orientation: @value', array(
    '@value' => $this
      ->getSetting('orientation'),
  ));
  $summary[] = $this
    ->t('Before label: @value', array(
    '@value' => $this
      ->getSetting('before_label'),
  ));
  $summary[] = $this
    ->t('After label: @value', array(
    '@value' => $this
      ->getSetting('after_label'),
  ));
  $summary[] = $this
    ->t('No overlay: @value', array(
    '@value' => $booleanToString[$this
      ->getSetting('no_overlay')],
  ));
  $summary[] = $this
    ->t('Move slider on hover: @value', array(
    '@value' => $booleanToString[$this
      ->getSetting('move_slider_on_hover')],
  ));
  $summary[] = $this
    ->t('Move with handle only: @value', array(
    '@value' => $booleanToString[$this
      ->getSetting('move_with_handle_only')],
  ));
  $summary[] = $this
    ->t('Click to move: @value', array(
    '@value' => $booleanToString[$this
      ->getSetting('click_to_move')],
  ));
  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.', array(
      '%value' => $cardinality > 0 ? $cardinality : 'unlimited',
    ));
  }
  return $summary;
}