summaryrefslogtreecommitdiffstats
path: root/src/Plugin/IndexRecordContentTransformation/RemoveSymbols.php
blob: d6e7e26fd0df77916af020f58774534e20cb6a46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php

namespace Drupal\views_natural_sort\Plugin\IndexRecordContentTransformation;

use Drupal\views_natural_sort\Plugin\IndexRecordContentTransformationBase as TransformationBase;

/**
 * @IndexRecordContentTransformation (
 *   id = "remove_symbols",
 *   label = @Translation("Remove Symbols")
 * )
 */
class RemoveSymbols extends TransformationBase {

  public function transform($string) {
    $symbols = $this->configuration['settings'];
    if (strlen($symbols) == 0) {
      return $string;
    }
    return preg_replace(
      '/[' . preg_quote($symbols) . ']/',
      '',
      $string
    );
  }

}