You are here

public function ResponsiveImageFormatter::settingsSummary in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/responsive_image/src/Plugin/Field/FieldFormatter/ResponsiveImageFormatter.php \Drupal\responsive_image\Plugin\Field\FieldFormatter\ResponsiveImageFormatter::settingsSummary()
  2. 9 core/modules/responsive_image/src/Plugin/Field/FieldFormatter/ResponsiveImageFormatter.php \Drupal\responsive_image\Plugin\Field\FieldFormatter\ResponsiveImageFormatter::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

core/modules/responsive_image/src/Plugin/Field/FieldFormatter/ResponsiveImageFormatter.php, line 169

Class

ResponsiveImageFormatter
Plugin for responsive image formatter.

Namespace

Drupal\responsive_image\Plugin\Field\FieldFormatter

Code

public function settingsSummary() {
  $summary = [];
  $responsive_image_style = $this->responsiveImageStyleStorage
    ->load($this
    ->getSetting('responsive_image_style'));
  if ($responsive_image_style) {
    $summary[] = t('Responsive image style: @responsive_image_style', [
      '@responsive_image_style' => $responsive_image_style
        ->label(),
    ]);
    $link_types = [
      'content' => t('Linked to content'),
      'file' => 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')];
    }
  }
  else {
    $summary[] = t('Select a responsive image style.');
  }
  return $summary;
}