Version 1
[yaffs-website] / web / core / modules / views / src / Plugin / views / area / TextCustom.php
diff --git a/web/core/modules/views/src/Plugin/views/area/TextCustom.php b/web/core/modules/views/src/Plugin/views/area/TextCustom.php
new file mode 100644 (file)
index 0000000..56e963d
--- /dev/null
@@ -0,0 +1,61 @@
+<?php
+
+namespace Drupal\views\Plugin\views\area;
+
+use Drupal\Core\Form\FormStateInterface;
+
+/**
+ * Views area text handler.
+ *
+ * @ingroup views_area_handlers
+ *
+ * @ViewsArea("text_custom")
+ */
+class TextCustom extends TokenizeAreaPluginBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function defineOptions() {
+    $options = parent::defineOptions();
+    $options['content'] = ['default' => ''];
+    return $options;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
+    parent::buildOptionsForm($form, $form_state);
+
+    $form['content'] = [
+      '#title' => $this->t('Content'),
+      '#type' => 'textarea',
+      '#default_value' => $this->options['content'],
+      '#rows' => 6,
+    ];
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function render($empty = FALSE) {
+    if (!$empty || !empty($this->options['empty'])) {
+      return [
+        '#markup' => $this->renderTextarea($this->options['content']),
+      ];
+    }
+
+    return [];
+  }
+
+  /**
+   * Render a text area with \Drupal\Component\Utility\Xss::filterAdmin().
+   */
+  public function renderTextarea($value) {
+    if ($value) {
+      return $this->sanitizeValue($this->tokenizeValue($value), 'xss_admin');
+    }
+  }
+
+}