You are here

class Xpath in Views XML Backend 8

Helper functions for handling XPath.

Hierarchy

  • class \Drupal\views_xml_backend\Xpath

Expanded class hierarchy of Xpath

9 files declare their use of Xpath
Date.php in src/Plugin/views/argument/Date.php
Contains \Drupal\views_xml_backend\Plugin\views\argument\Date.
DayDate.php in src/Plugin/views/argument/DayDate.php
Contains \Drupal\views_xml_backend\Plugin\views\argument\DayDate.
MonthDate.php in src/Plugin/views/argument/MonthDate.php
Contains \Drupal\views_xml_backend\Plugin\views\argument\MonthDate.
Numeric.php in src/Plugin/views/filter/Numeric.php
Contains \Drupal\views_xml_backend\Plugin\views\filter\Numeric.
Standard.php in src/Plugin/views/filter/Standard.php
Contains \Drupal\views_xml_backend\Plugin\views\filter\Standard.

... See full list

File

src/Xpath.php, line 13
Contains \Drupal\views_xml_backend\Xpath.

Namespace

Drupal\views_xml_backend
View source
class Xpath {

  /**
   * Escapes an XPath string.
   *
   * @param string $argument
   *   The string to escape.
   *
   * @return string
   *   The escaped string.
   */
  public static function escapeXpathString($argument) {
    if (strpos($argument, "'") === FALSE) {
      return "'" . $argument . "'";
    }
    if (strpos($argument, '"') === FALSE) {
      return '"' . $argument . '"';
    }
    $string = $argument;
    $parts = [];

    // XPath doesn't provide a way to escape quotes in strings, so we break up
    // the string and return a concat() function call.
    while (TRUE) {
      if (FALSE !== ($pos = strpos($string, "'"))) {
        $parts[] = sprintf("'%s'", substr($string, 0, $pos));
        $parts[] = "\"'\"";
        $string = substr($string, $pos + 1);
      }
      else {
        $parts[] = "'{$string}'";
        break;
      }
    }
    return sprintf('concat(%s)', implode($parts, ', '));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Xpath::escapeXpathString public static function Escapes an XPath string.