You are here

public function Search404Controller::search404CustomRedirection in Search 404 8

Same name and namespace in other branches
  1. 2.x src/Controller/Search404Controller.php \Drupal\search404\Controller\Search404Controller::search404CustomRedirection()

Helper function to make a redirection path with custom path.

Parameters

string $search_type: Which type of search.

string $path: Searched url or keyword in the address bar.

string $keys: Searching keywords.

Return value

array Custom redirection path and key for comparison.

1 call to Search404Controller::search404CustomRedirection()
Search404Controller::search404Page in src/Controller/Search404Controller.php

File

src/Controller/Search404Controller.php, line 455

Class

Search404Controller
Route controller for search.

Namespace

Drupal\search404\Controller

Code

public function search404CustomRedirection($search_type, $path, $keys) {
  $search['keys'] = $keys;
  $search['path'] = $path;

  // If search keywords has space or hyphen or slash.
  if (preg_match('/-|%20/', $search['path']) || stripos($search['path'], '/') !== FALSE) {
    $search['keys'] = str_replace($search_type, '-', $search['keys']);
    if (preg_match('/%20/', $search['path'])) {
      $search['path'] = str_replace('%20', '-', $search['path']);
    }

    // If search keywords has slash.
    if (stripos($search['path'], '/') !== FALSE) {
      $search['keys'] = str_replace($search_type, '-', $search['keys']);
      $search['path'] = str_replace('/', '-', $search['path']);
      $search['path'] = substr_replace($search['path'], '/', 0, 1);
      $search['path'] = rtrim($search['path'], "-");
    }
  }
  return $search;
}