You are here

trait ViewsAddButtonTrait in Views Add Button 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/views/ViewsAddButtonTrait.php \Drupal\views_add_button\Plugin\views\ViewsAddButtonTrait

Hierarchy

2 files declare their use of ViewsAddButtonTrait
ViewsAddButtonArea.php in src/Plugin/views/area/ViewsAddButtonArea.php
ViewsAddButtonField.php in src/Plugin/views/field/ViewsAddButtonField.php

File

src/Plugin/views/ViewsAddButtonTrait.php, line 5

Namespace

Drupal\views_add_button\Plugin\views
View source
trait ViewsAddButtonTrait {
  public function viewsAddButtonCleanupSpecialCharacters($str = '') {

    /*
     * Perform bracket and special character replacement.
     * For security reasons, we are not opening this to most characters.
     * @see https://www.drupal.org/project/views_add_button/issues/3095849
     */
    $replace = [
      '%5B' => '[',
      '%5D' => ']',
      '&' => '&',
    ];
    return strtr($str, $replace);
  }
  public function getQueryString($values = NULL) {
    $query_string = $this->options['query_string'];
    $q = NULL;
    if (isset($value->index)) {
      $q = $this->options['tokenize'] ? $this
        ->tokenizeValue($query_string, $values->index) : $query_string;
    }
    else {
      $q = $this->options['tokenize'] ? $this
        ->tokenizeValue($query_string) : $query_string;
    }
    $query_opts = [];
    if ($q) {
      $q = $this
        ->viewsAddButtonCleanupSpecialCharacters($q);
      $qparts = explode('&', $q);
      foreach ($qparts as $part) {
        $p = explode('=', $part);
        if (is_array($p) && count($p) > 1) {
          $query_opts[$p[0]] = $p[1];
        }
      }
    }
    return $query_opts;
  }

}

Members