You are here

public function ImageEmbedDataFormatter::settingsSummary in Formatter Suite 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/ImageEmbedDataFormatter.php, line 68

Class

ImageEmbedDataFormatter
Embeds an image as a data URL instead of a file URL.

Namespace

Drupal\formatter_suite\Plugin\Field\FieldFormatter

Code

public function settingsSummary() {

  // Get current settings.
  $maximumEmbedWidth = $this
    ->getSetting('maximumEmbedWidth');
  $maximumEmbedHeight = $this
    ->getSetting('maximumEmbedHeight');

  // Sanitize & validate.
  //
  // Security: The maximum embed width and height have been entered by
  // an administrator. They both should be simple integers and should
  // not include any HTML or HTML entities.
  //
  // Parsing these as integers ignores any extra text that may be in
  // the value.
  if (isset($maximumEmbedWidth) === TRUE) {
    $maximumEmbedWidth = intval($maximumEmbedWidth);
  }
  else {
    $maximumEmbedWidth = 0;
  }
  if (isset($maximumEmbedHeight) === TRUE) {
    $maximumEmbedHeight = intval($maximumEmbedHeight);
  }
  else {
    $maximumEmbedHeight = 0;
  }

  // Summarize.
  $summary = [];
  $summary[] = $this
    ->t('Embed image data URL');
  if ($maximumEmbedWidth > 0 && $maximumEmbedHeight > 0) {
    $summary[] = $this
      ->t('  for width ≤ @maximumEmbedWidth & height ≤ @maximumEmbedHeight.', [
      '@maximumEmbedWidth' => $maximumEmbedWidth,
      '@maximumEmbedHeight' => $maximumEmbedHeight,
    ]);
  }
  elseif ($maximumEmbedWidth > 0) {
    $summary[] = $this
      ->t('  for width ≤ @maximumEmbedWidth & any height.', [
      '@maximumEmbedWidth' => $maximumEmbedWidth,
    ]);
  }
  elseif ($maximumEmbedHeight > 0) {
    $summary[] = $this
      ->t('  for any width & height ≤ @maximumEmbedHeight.', [
      '@maximumEmbedHeight' => $maximumEmbedHeight,
    ]);
  }
  else {
    $summary[] = $this
      ->t('  for any width & height.');
  }
  $summary = array_merge($summary, parent::settingsSummary());
  return $summary;
}