You are here

public function PatternFormatter::settingsSummary in UI Patterns Field Formatters 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/PatternFormatter.php, line 171

Class

PatternFormatter
Plugin implementation of the 'pattern' formatter.

Namespace

Drupal\ui_patterns_field_formatters\Plugin\Field\FieldFormatter

Code

public function settingsSummary() {
  $summary = [];
  $pattern = $this
    ->getSetting('pattern');
  if (!empty($pattern)) {
    $pattern_definition = $this->patternsManager
      ->getDefinition($pattern);
    $label = $this
      ->t('None');
    if (!empty($this
      ->getSetting('pattern'))) {
      $label = $pattern_definition
        ->getLabel();
    }
    $summary[] = $this
      ->t('Pattern: @pattern', [
      '@pattern' => $label,
    ]);
    $pattern_variant = $this
      ->getCurrentVariant($pattern);
    if (isset($pattern_variant)) {
      $variant = $this
        ->getSetting('variants')[$pattern_definition
        ->id()];
      $variant = $pattern_definition
        ->getVariant($variant)
        ->getLabel();
      $summary[] = $this
        ->t('Variant: @variant', [
        '@variant' => $variant,
      ]);
    }
  }
  return $summary;
}