You are here

public function PatternWrapperEntityReferenceFormatter::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 EntityReferenceEntityFormatter::settingsSummary

File

src/Plugin/Field/FieldFormatter/PatternWrapperEntityReferenceFormatter.php, line 151

Class

PatternWrapperEntityReferenceFormatter
Plugin implementation of 'pattern_wrapper_entity_reference_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;
}