You are here

public function GeneralUserReferenceFormatter::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 FormatterBase::settingsSummary

File

src/Plugin/Field/FieldFormatter/GeneralUserReferenceFormatter.php, line 310

Class

GeneralUserReferenceFormatter
Formats a user entity reference as one or more links.

Namespace

Drupal\formatter_suite\Plugin\Field\FieldFormatter

Code

public function settingsSummary() {

  // Sanitize current settings.
  $this
    ->sanitizeSettings();
  $isMultiple = $this->fieldDefinition
    ->getFieldStorageDefinition()
    ->isMultiple();

  // Summarize.
  $summary = [];
  $styles = self::getUserReferenceStyles();
  $style = $this
    ->getSetting('userReferenceStyle');
  if (isset($styles[$style]) === TRUE) {
    $summary[] = $styles[$style];
  }
  else {
    $summary[] = $this
      ->t("Unknown style");
  }
  if ($this
    ->getSetting('showLink') === FALSE) {
    $summary[] = $this
      ->t('No link');
  }
  else {
    switch ($this
      ->getSetting('openLinkIn')) {
      case '_self':
        $summary[] = $this
          ->t('Open in current tab/window');
        break;
      case '_blank':
        $summary[] = $this
          ->t('Open in new tab/window');
        break;
      case 'download':
        $summary[] = $this
          ->t('Download');
        break;
    }
  }

  // If the field can store multiple values, then summarize list style.
  if ($isMultiple === TRUE) {
    $listStyles = self::getListStyles();
    $listStyle = $this
      ->getSetting('listStyle');
    $listSeparator = $this
      ->getSetting('listSeparator');
    $text = $listStyles[$listStyle];
    if ($listStyle === 'span' && empty($listSeparator) === FALSE) {
      $text .= $this
        ->t(', with separator');
    }
    $summary[] = $text;
  }
  return $summary;
}