Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / views / src / Plugin / views / filter / StringFilter.php
index a9ab5a1861bbd517cabfed5519dfb8655593e83f..f6b7e248223d4e4347bf3102c443bf4ccbabfb32 100644 (file)
@@ -27,10 +27,33 @@ class StringFilter extends FilterPluginBase {
     $options = parent::defineOptions();
 
     $options['expose']['contains']['required'] = ['default' => FALSE];
+    $options['expose']['contains']['placeholder'] = ['default' => ''];
 
     return $options;
   }
 
+  /**
+   * {@inheritdoc}
+   */
+  public function defaultExposeOptions() {
+    parent::defaultExposeOptions();
+    $this->options['expose']['placeholder'] = NULL;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function buildExposeForm(&$form, FormStateInterface $form_state) {
+    parent::buildExposeForm($form, $form_state);
+    $form['expose']['placeholder'] = [
+      '#type' => 'textfield',
+      '#default_value' => $this->options['expose']['placeholder'],
+      '#title' => $this->t('Placeholder'),
+      '#size' => 40,
+      '#description' => $this->t('Hint text that appears inside the field when empty.'),
+    ];
+  }
+
   /**
    * This kind of construct makes it relatively easy for a child class
    * to add or remove functionality by overriding this function and
@@ -211,6 +234,9 @@ class StringFilter extends FilterPluginBase {
         '#size' => 30,
         '#default_value' => $this->value,
       ];
+      if (!empty($this->options['expose']['placeholder'])) {
+        $form['value']['#attributes']['placeholder'] = $this->options['expose']['placeholder'];
+      }
       $user_input = $form_state->getUserInput();
       if ($exposed && !isset($user_input[$identifier])) {
         $user_input[$identifier] = $this->value;