You are here

protected function GeneralEmailFormatter::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

2 calls to GeneralEmailFormatter::sanitizeSettings()
GeneralEmailFormatter::settingsForm in src/Plugin/Field/FieldFormatter/GeneralEmailFormatter.php
Returns a form to configure settings for the formatter.
GeneralEmailFormatter::settingsSummary in src/Plugin/Field/FieldFormatter/GeneralEmailFormatter.php
Returns a short summary for the current formatter settings.

File

src/Plugin/Field/FieldFormatter/GeneralEmailFormatter.php, line 315

Class

GeneralEmailFormatter
Formats an email address.

Namespace

Drupal\formatter_suite\Plugin\Field\FieldFormatter

Code

protected function sanitizeSettings() {

  // Get settings.
  $emailStyle = $this
    ->getSetting('emailStyle');
  $linkText = $this
    ->getSetting('linkText');
  $defaults = $this
    ->defaultSettings();
  $isMultiple = $this->fieldDefinition
    ->getFieldStorageDefinition()
    ->isMultiple();

  // Sanitize & validate.
  $emailStyles = $this
    ->getEmailStyles();
  if (empty($emailStyle) === TRUE || isset($emailStyles[$emailStyle]) === FALSE) {
    $emailStyle = $defaults['emailStyle'];
    $this
      ->setSetting('emailStyle', $emailStyle);
  }
  if (empty($linkText) === TRUE) {

    // Link text is further sanitized during use.
    $linkText = $defaults['linkText'];
    $this
      ->setSetting('linkText', $linkText);
  }
  $listStyle = $this
    ->getSetting('listStyle');
  $listStyles = $this
    ->getListStyles();
  if ($isMultiple === TRUE) {
    if (empty($listStyle) === TRUE || isset($listStyles[$listStyle]) === FALSE) {
      $listStyle = $defaults['listStyle'];
      $this
        ->setSetting('listStyle', $listStyle);
    }
  }

  // Classes and custom title text are not sanitized or validated.
  // They will be added to the link, with appropriate Xss filtering.
}