You are here

public function AdvancedTextFormatter::settingsSummary in Advanced Text Formatter 8

Same name and namespace in other branches
  1. 2.1.x src/Plugin/Field/FieldFormatter/AdvancedTextFormatter.php \Drupal\advanced_text_formatter\Plugin\Field\FieldFormatter\AdvancedTextFormatter::settingsSummary()
  2. 2.0.x src/Plugin/Field/FieldFormatter/AdvancedTextFormatter.php \Drupal\advanced_text_formatter\Plugin\Field\FieldFormatter\AdvancedTextFormatter::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/AdvancedTextFormatter.php, line 191

Class

AdvancedTextFormatter
Plugin implementation of the 'advanced_text_formatter' formatter.

Namespace

Drupal\advanced_text_formatter\Plugin\Field\FieldFormatter

Code

public function settingsSummary() {
  $summary = [];
  $yes = $this
    ->t('Yes');
  $no = $this
    ->t('No');
  if ($this
    ->getSetting('trim_length') > 0) {
    $summary[] = $this
      ->t('Trim length: @length', [
      '@length' => $this
        ->getSetting('trim_length'),
    ]);
    $summary[] = $this
      ->t('Ellipsis: @ellipsis', [
      '@ellipsis' => $this
        ->getSetting('ellipsis') ? $yes : $no,
    ]);
    $summary[] = $this
      ->t('Word Boundary: @word', [
      '@word' => $this
        ->getSetting('word_boundary') ? $yes : $no,
    ]);
    $summary[] = $this
      ->t('Use Summary: @summary', [
      '@summary' => $this
        ->getSetting('use_summary') ? $yes : $no,
    ]);
  }
  $summary[] = $this
    ->t('Token Replace: @token', [
    '@token' => $this
      ->getSetting('token_replace') ? $yes : $no,
  ]);
  switch ($this
    ->getSetting('filter')) {
    case static::FORMAT_DRUPAL:
      $formats = filter_formats();
      $format = $this
        ->getSetting('format');
      $format = isset($formats[$format]) ? $formats[$format]
        ->get('name') : $this
        ->t('Unknown');
      $summary[] = $this
        ->t('Filter: @filter', [
        '@filter' => $this
          ->t('Drupal'),
      ]);
      $summary[] = $this
        ->t('Format: @format', [
        '@format' => $format,
      ]);
      break;
    case static::FORMAT_PHP:
      $text = [];
      $tags = $this
        ->getSetting('allowed_html');
      $autop = $this
        ->getSetting('autop');
      if (is_array($tags) && !empty($tags)) {
        $tags = '<' . implode('> <', $tags) . '>';
      }
      if (empty($tags)) {
        $text[] = $this
          ->t('Remove all HTML tags.');
      }
      else {
        $text[] = $this
          ->t('Limit allowed HTML tags: @tags.', [
          '@tags' => $tags,
        ]);
      }
      if (!empty($autop)) {
        $text[] = $this
          ->t('Convert line breaks into HTML.');
      }
      $summary[] = $this
        ->t('Filter: @filter', [
        '@filter' => implode(' ', $text),
      ]);
      break;
    case static::FORMAT_INPUT:
      $summary[] = $this
        ->t('Filter: @filter', [
        '@filter' => $this
          ->t('Selected Text Format'),
      ]);
      break;
    default:
      $summary[] = $this
        ->t('Filter: @filter', [
        '@filter' => $this
          ->t('None'),
      ]);
      break;
  }
  $summary = array_filter($summary);
  return $summary;
}