You are here

public function ViewsFieldFormatter::settingsSummary in Views field formatter 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/Field/FieldFormatter/ViewsFieldFormatter.php \Drupal\views_field_formatter\Plugin\Field\FieldFormatter\ViewsFieldFormatter::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/ViewsFieldFormatter.php, line 205

Class

ViewsFieldFormatter
Class ViewsFieldFormatter.

Namespace

Drupal\views_field_formatter\Plugin\Field\FieldFormatter

Code

public function settingsSummary() {
  $summary = [];
  $settings = $this
    ->getSettings();

  // For default settings, don't show a summary.
  if ($settings['view'] === '') {
    return [
      $this
        ->t('Not configured yet.'),
    ];
  }
  list($view, $view_display) = \explode('::', $settings['view'], 2);
  $multiple = (bool) $settings['multiple'] === TRUE ? 'Enabled' : 'Disabled';
  $hide_empty = (bool) $settings['hide_empty'] === TRUE ? 'Hide' : 'Display';
  $arguments = \array_filter($settings['arguments'], static function ($argument) {
    return $argument['checked'];
  });
  $all_arguments = $this
    ->getDefaultArguments();
  $arguments = \array_map(static function ($argument) use ($all_arguments) {
    return $all_arguments[$argument];
  }, \array_keys($arguments));
  if ([] === $arguments) {
    $arguments[] = $this
      ->t('None');
  }
  if ($view !== NULL) {
    $summary[] = \t('View: @view', [
      '@view' => $view,
    ]);
    $summary[] = \t('Display: @display', [
      '@display' => $view_display,
    ]);
    $summary[] = \t('Argument(s): @arguments', [
      '@arguments' => \implode(', ', $arguments),
    ]);
    $summary[] = \t('Empty views: @hide_empty empty views', [
      '@hide_empty' => $hide_empty,
    ]);
    $summary[] = \t('Multiple: @multiple', [
      '@multiple' => $multiple,
    ]);
  }
  if ((bool) $settings['multiple'] === TRUE && $settings['implode_character'] !== '') {
    $summary[] = \t('Implode character: @character', [
      '@character' => $settings['implode_character'],
    ]);
  }
  return $summary;
}