summaryrefslogtreecommitdiffstats
path: root/src/Plugin/IndexRecordContentTransformation/RemoveBeginningWords.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Plugin/IndexRecordContentTransformation/RemoveBeginningWords.php')
-rw-r--r--src/Plugin/IndexRecordContentTransformation/RemoveBeginningWords.php29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/Plugin/IndexRecordContentTransformation/RemoveBeginningWords.php b/src/Plugin/IndexRecordContentTransformation/RemoveBeginningWords.php
new file mode 100644
index 0000000..e773ba1
--- /dev/null
+++ b/src/Plugin/IndexRecordContentTransformation/RemoveBeginningWords.php
@@ -0,0 +1,29 @@
+<?php
+
+namespace Drupal\views_natural_sort\Plugin\IndexRecordContentTransformation;
+
+use Drupal\views_natural_sort\Plugin\IndexRecordContentTransformationBase as TransformationBase;
+
+/**
+ * @IndexRecordContentTransformation (
+ * id = "remove_beginning_words",
+ * label = @Translation("Remove Beginning Words")
+ * )
+ */
+class RemoveBeginningWords extends TransformationBase {
+
+ public function transform($string) {
+ $beginning_words = $this->configuration['settings'];
+ if (empty($beginning_words)) {
+ return $string;
+ }
+
+ array_walk($beginning_words, 'preg_quote');
+ return preg_replace(
+ '/^(' . implode('|', $beginning_words) . ')\s+/i',
+ '',
+ $string
+ );
+ }
+
+}