protected function NameFormatParser::applyModifiers in Name Field 8
Applies the specified modifiers to the string.
Parameters
string $string: The token string to process.
string $modifiers: The modifiers to apply.
Return value
string The processed string.
1 call to NameFormatParser::applyModifiers()
- NameFormatParser::addComponent in src/
NameFormatParser.php  - Adds a component.
 
File
- src/
NameFormatParser.php, line 281  
Class
- NameFormatParser
 - Converts a name from an array of components into a defined format.
 
Namespace
Drupal\nameCode
protected function applyModifiers($string, $modifiers) {
  if (!is_null($string) || strlen($string)) {
    if ($modifiers) {
      $prefix = '';
      $suffix = '';
      if (preg_match('/^(<span[^>]*>)(.*)(<\\/span>)$/i', $string, $matches)) {
        $prefix = $matches[1];
        $string = $matches[2];
        $suffix = $matches[3];
      }
      for ($j = 0; $j < strlen($modifiers); $j++) {
        switch ($modifiers[$j]) {
          case 'L':
            $string = mb_strtolower($string);
            break;
          case 'U':
            $string = mb_strtoupper($string);
            break;
          case 'F':
            $string = Unicode::ucfirst($string);
            break;
          case 'G':
            $string = UniCode::ucwords($string);
            break;
          case 'T':
            $string = trim(preg_replace('/\\s+/', ' ', $string));
            break;
          case 'S':
            $string = Html::escape($string);
            break;
          case 'B':
            $parts = preg_split($this->boundaryRegExp, $string);
            $string = (string) array_shift($parts);
            break;
          case 'b':
            $parts = preg_split($this->boundaryRegExp, $string);
            $string = (string) array_pop($parts);
            break;
        }
      }
      $string = $prefix . $string . $suffix;
    }
  }
  return $string;
}