protected function QueryString::getUrlForRequest in Facets 8
Gets the URL object for a request.
This method statically caches the URL object for a request based on the facet source path. This reduces subsequent calls to the processor from having to regenerate the URL object.
Parameters
string $facet_source_path: The facet source path.
\Symfony\Component\HttpFoundation\Request $request: The request.
Return value
\Drupal\Core\Url The URL.
1 call to QueryString::getUrlForRequest()
- QueryString::buildUrls in src/
Plugin/ facets/ url_processor/ QueryString.php - Adds urls to the results.
File
- src/
Plugin/ facets/ url_processor/ QueryString.php, line 280
Class
- QueryString
- Query string URL processor.
Namespace
Drupal\facets\Plugin\facets\url_processorCode
protected function getUrlForRequest($facet_source_path, Request $request) {
/** @var \Drupal\Core\Url[] $requestUrlsByPath */
$requestUrlsByPath =& drupal_static(__CLASS__ . __FUNCTION__, []);
if (array_key_exists($facet_source_path, $requestUrlsByPath)) {
return $requestUrlsByPath[$facet_source_path];
}
// Try to grab any route params from the original request.
// In case of request path not having a matching route, Url generator will
// fail with.
try {
$requestUrl = Url::createFromRequest($request);
} catch (ResourceNotFoundException $e) {
// Bypass exception if no path available.
// Should be unreachable in default FacetSource implementations,
// but you never know.
if (!$facet_source_path) {
throw $e;
}
$requestUrl = Url::fromUserInput($facet_source_path, [
'query' => [
'_format' => $this->request
->get('_format'),
],
]);
}
$requestUrl
->setOption('attributes', [
'rel' => 'nofollow',
]);
$requestUrlsByPath[$facet_source_path] = $requestUrl;
return $requestUrl;
}