public function GeneralFileLinkFormatter::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/ GeneralFileLinkFormatter.php, line 245
Class
- GeneralFileLinkFormatter
- Formats a file field as one or more links.
Namespace
Drupal\formatter_suite\Plugin\Field\FieldFormatterCode
public function settingsSummary() {
// Sanitize current settings.
$this
->sanitizeSettings();
$isMultiple = $this->fieldDefinition
->getFieldStorageDefinition()
->isMultiple();
// Summarize.
$summary = [];
$text = '';
switch ($this
->getSetting('titleStyle')) {
case 'text_from_filename':
$text .= (string) $this
->t('Show filename');
break;
case 'text_from_link':
$text .= (string) $this
->t('Show description');
break;
case 'text_custom':
$text .= (string) $this
->t('Show custom text');
break;
}
if ($this
->getSetting('showSize') === TRUE) {
$text .= (string) $this
->t(', size');
}
if ($this
->getSetting('showIcon') === TRUE) {
$text .= (string) $this
->t(', MIME icon');
}
$summary[] = $text;
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 = $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;
}