You are here

public function GeneralLinkFormatter::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/GeneralLinkFormatter.php, line 155

Class

GeneralLinkFormatter
Formats a link field 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 = [];
  switch ($this
    ->getSetting('titleStyle')) {
    case 'text_from_link':
      $summary[] = $this
        ->t('Show field title');
      break;
    case 'text_from_url':
      $summary[] = $this
        ->t('Show field URL');
      break;
    case 'text_custom':
      $summary[] = $this
        ->t('Show custom text');
      break;
  }
  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;
    }
    $text = '';
    if ($this
      ->getSetting('noreferrer') === TRUE) {
      $text .= 'noreferrer ';
    }
    if ($this
      ->getSetting('noopener') === TRUE) {
      $text .= 'noopener ';
    }
    if ($this
      ->getSetting('nofollow') === TRUE) {
      $text .= 'nofollow ';
    }
    if (empty($text) === FALSE) {
      $summary[] = $text;
    }
  }

  // If the field can store multiple values, then summarize list style.
  if ($isMultiple === TRUE) {
    $listStyles = $this
      ->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;
}