public function TextWithExpandCollapseButtonsFormatter::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/ TextWithExpandCollapseButtonsFormatter.php, line 57
Class
- TextWithExpandCollapseButtonsFormatter
- Formats text with expand/collapse buttons to show more/less.
Namespace
Drupal\formatter_suite\Plugin\Field\FieldFormatterCode
public function settingsSummary() {
// Get current settings.
$collapsedHeight = $this
->getSetting('collapsedHeight');
$animationDuration = $this
->getSetting('animationDuration');
// Security: The animation duration is entered by an administrator.
// It should be a simple integer, with no other characters, HTML, or
// HTML entities.
//
// By parsing it as an integer, we ignore anything else and remove
// any security issues.
$animationDuration = intval($animationDuration);
// Security: The collapse height is entered by an administrator.
// It should be a number followed by CSS units, such as "px", "pt",
// or "em". It should not contain HTML or HTML entities.
//
// If integer parsing of the string yields a zero, then the string
// is assumed to be empty or invalid and collapsing is disabled.
// Otherwise the string is santized using an Html escape filter
// that escapes all HTML and HTML entities. If the admin enters these,
// the resulting string is not likely to work as a collapse height
// and the Javascript will not get a meaningful result, but it will
// still be safe.
$collapsedHeight = Html::escape($collapsedHeight);
$hasCollapseHeight = TRUE;
if (empty($collapsedHeight) === TRUE || $collapsedHeight === "0" || (int) $collapsedHeight === 0) {
$hasCollapseHeight = FALSE;
}
// Present.
$summary = parent::settingsSummary();
if ($hasCollapseHeight === FALSE) {
$summary[] = $this
->t('Disabled because no collapsed height set.');
}
else {
$summary[] = $this
->t('Shorten long text areas to @collapsedHeight.', [
'@collapsedHeight' => $collapsedHeight,
]);
if ($animationDuration > 0) {
$summary[] = $this
->t('Animate over @animationDuration milliseconds.', [
'@animationDuration' => $animationDuration,
]);
}
}
return $summary;
}