You are here

protected function SaveSearch::getCurrentPath in Search API Saved Searches 8

Retrieves a sanitized version of the current path.

Return value

string The current path, relative to the Drupal installation.

1 call to SaveSearch::getCurrentPath()
SaveSearch::build in src/Plugin/Block/SaveSearch.php
Builds and returns the renderable array for this block plugin.

File

src/Plugin/Block/SaveSearch.php, line 310

Class

SaveSearch
Displays the "Save search" form in a block.

Namespace

Drupal\search_api_saved_searches\Plugin\Block

Code

protected function getCurrentPath() {

  // Get the current path.
  $path = $this
    ->getRequestStack()
    ->getCurrentRequest()
    ->getRequestUri();

  // Remove the Drupal base path, if any.
  $base_path = rtrim(base_path(), '/');
  $base_path_length = strlen($base_path);
  if ($base_path && substr($path, 0, $base_path_length) === $base_path) {
    $path = substr($path, $base_path_length);
  }

  // Remove AJAX parameters.
  $path = preg_replace('/([?&])(ajax_form|_wrapper_format)=[^&#]+/', '$1', $path);

  // Sanitize empty GET parameter arrays.
  $path = preg_replace('/\\?(#|$)/', '$1', $path);
  return $path;
}