summaryrefslogtreecommitdiffstats
path: root/src/Plugin/IndexRecordContentTransformation/RemoveBeginningWords.php
diff options
context:
space:
mode:
authorAllan Chappell2016-12-25 03:57:09 (GMT)
committerAllan Chappell2016-12-25 03:57:09 (GMT)
commitd6ff0975399502df7a829ac2b06deaacff8f9cdb (patch)
tree0f2cb825d5af15261e8474f46ee5bcaa1d284e2a /src/Plugin/IndexRecordContentTransformation/RemoveBeginningWords.php
parent96c2cce62a4aa8315547622a39042de7a5fc1838 (diff)
Added plugins for the transformation system and refactored VNS entries into an object.
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
+ );
+ }
+
+}