You are here

protected function GeneralNumberWithMinMaxFormatter::sanitizeSettings in Formatter Suite 8

Sanitize settings to insure that they are safe and valid.

@internal Drupal's class hierarchy for plugins and their settings does not include a 'validate' function, like that for other classes with forms. Validation must therefore occur on use, rather than on form submission. @endinternal

Overrides GeneralNumberFormatter::sanitizeSettings

1 call to GeneralNumberWithMinMaxFormatter::sanitizeSettings()
GeneralNumberWithMinMaxFormatter::settingsSummary in src/Plugin/Field/FieldFormatter/GeneralNumberWithMinMaxFormatter.php
Returns a short summary for the current formatter settings.

File

src/Plugin/Field/FieldFormatter/GeneralNumberWithMinMaxFormatter.php, line 252

Class

GeneralNumberWithMinMaxFormatter
Formats with a variety of notation styles and includes field min/max.

Namespace

Drupal\formatter_suite\Plugin\Field\FieldFormatter

Code

protected function sanitizeSettings() {

  // Get settings.
  $commonFormat = $this
    ->getSetting('commonFormat');
  $commonFormats = $this
    ->getCommonFormats();
  $defaults = $this
    ->defaultSettings();

  // Sanitize & validate.
  parent::sanitizeSettings();

  // Disable the parent's prefix/suffix support.
  $this
    ->setSetting('usePrefixAndSuffix', FALSE);
  if (empty($commonFormat) === TRUE || isset($commonFormats[$commonFormat]) === FALSE) {
    $commonFormat = $defaults['commonFormat'];
    $this
      ->setSetting('commonFormat', $commonFormat);
  }

  // The custom format string is sanitized later during use.
}