You are here

trait TokensDateFilterTrait in Tokens in Views Filter Criteria 8

Trait for Tokens Date Filter.

Hierarchy

2 files declare their use of TokensDateFilterTrait
TokensDateFilter.php in src/Plugin/views/filter/token/TokensDateFilter.php
TokensDateTimeFilter.php in src/Plugin/views/filter/token/TokensDateTimeFilter.php

File

src/TokensDateFilterTrait.php, line 10

Namespace

Drupal\token_views_filter
View source
trait TokensDateFilterTrait {

  /**
   * {@inheritdoc}
   */
  public function validateOptionsForm(&$form, FormStateInterface $form_state) {

    // Replace tokens to validate date.
    $options = $form_state
      ->getValue('options');
    $value =& $options['value'];
    $original_value = $value;
    $this
      ->replaceTokens($value);
    $form_state
      ->setValue('options', $options);
    parent::validateOptionsForm($form, $form_state);

    // Restore tokens to use it in filters.
    $options['value'] = $original_value;
    $form_state
      ->setValue('options', $options);
  }

  /**
   * {@inheritdoc}
   */
  public function validateExposed(&$form, FormStateInterface $form_state) {

    // Replace tokens to validate date.
    $options = $form_state
      ->getValue('options');
    $value =& $options['value'];
    $original_value = $value;
    $this
      ->replaceTokens($value);
    $form_state
      ->setValue('options', $options);
    parent::validateExposed($form, $form_state);

    // Restore tokens to use it in filters.
    $options['value'] = $original_value;
    $form_state
      ->setValue('options', $options);
  }

}

Members