Version 1
[yaffs-website] / web / core / modules / filter / src / Plugin / Filter / FilterUrl.php
diff --git a/web/core/modules/filter/src/Plugin/Filter/FilterUrl.php b/web/core/modules/filter/src/Plugin/Filter/FilterUrl.php
new file mode 100644 (file)
index 0000000..d3d2c96
--- /dev/null
@@ -0,0 +1,52 @@
+<?php
+
+namespace Drupal\filter\Plugin\Filter;
+
+use Drupal\Core\Form\FormStateInterface;
+use Drupal\filter\FilterProcessResult;
+use Drupal\filter\Plugin\FilterBase;
+
+/**
+ * Provides a filter to convert URLs into links.
+ *
+ * @Filter(
+ *   id = "filter_url",
+ *   title = @Translation("Convert URLs into links"),
+ *   type = Drupal\filter\Plugin\FilterInterface::TYPE_MARKUP_LANGUAGE,
+ *   settings = {
+ *     "filter_url_length" = 72
+ *   }
+ * )
+ */
+class FilterUrl extends FilterBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function settingsForm(array $form, FormStateInterface $form_state) {
+    $form['filter_url_length'] = [
+      '#type' => 'number',
+      '#title' => $this->t('Maximum link text length'),
+      '#default_value' => $this->settings['filter_url_length'],
+      '#min' => 1,
+      '#field_suffix' => $this->t('characters'),
+      '#description' => $this->t('URLs longer than this number of characters will be truncated to prevent long strings that break formatting. The link itself will be retained; just the text portion of the link will be truncated.'),
+    ];
+    return $form;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function process($text, $langcode) {
+    return new FilterProcessResult(_filter_url($text, $this));
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function tips($long = FALSE) {
+    return $this->t('Web page addresses and email addresses turn into links automatically.');
+  }
+
+}