Commit 4945bae2 authored by webchick's avatar webchick

Issue #2238945 by effulgentsia: Remove the 'clean_urls' request attribute.

parent ea22b219
...@@ -50,13 +50,7 @@ public function onKernelRequestConvertPath(GetResponseEvent $event) { ...@@ -50,13 +50,7 @@ public function onKernelRequestConvertPath(GetResponseEvent $event) {
$path = trim($request->getPathInfo(), '/'); $path = trim($request->getPathInfo(), '/');
$path = $this->pathProcessor->processInbound($path, $request); $path = $this->pathProcessor->processInbound($path, $request);
$request->attributes->set('_system_path', $path); $request->attributes->set('_system_path', $path);
// Also set an attribute that indicates whether we are using clean URLs.
$clean_urls = TRUE;
$base_url = $request->getBaseUrl();
if (!empty($base_url) && strpos($base_url, $request->getScriptName()) !== FALSE) {
$clean_urls = FALSE;
}
$request->attributes->set('clean_urls', $clean_urls);
// Set the cache key on the alias manager cache decorator. // Set the cache key on the alias manager cache decorator.
if ($event->getRequestType() == HttpKernelInterface::MASTER_REQUEST) { if ($event->getRequestType() == HttpKernelInterface::MASTER_REQUEST) {
$this->aliasManager->setCacheKey($path); $this->aliasManager->setCacheKey($path);
......
...@@ -128,4 +128,25 @@ public static function duplicate(Request $original_request, $uri, $method = 'GET ...@@ -128,4 +128,25 @@ public static function duplicate(Request $original_request, $uri, $method = 'GET
return $request; return $request;
} }
/**
* Returns whether the request is using a clean URL.
*
* A clean URL is one that does not include the script name. For example,
* - http://example.com/node/1 is a clean URL.
* - http://example.com/index.php/node/1 is not a clean URL.
*
* Unclean URLs are required on sites hosted by web servers that cannot be
* configured to implicitly route URLs to index.php.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The request.
*
* @return bool
* TRUE if the request is using a clean URL.
*/
public static function isCleanUrl(Request $request) {
$base_url = $request->getBaseUrl();
return (empty($base_url) || strpos($base_url, $request->getScriptName()) === FALSE);
}
} }
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
use Drupal\Core\Config\Entity\ConfigEntityBase; use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\Core\Config\Entity\EntityWithPluginBagInterface; use Drupal\Core\Config\Entity\EntityWithPluginBagInterface;
use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Routing\RequestHelper;
use Drupal\image\ImageEffectBag; use Drupal\image\ImageEffectBag;
use Drupal\image\ImageEffectInterface; use Drupal\image\ImageEffectInterface;
use Drupal\image\ImageStyleInterface; use Drupal\image\ImageStyleInterface;
...@@ -208,7 +209,7 @@ public function buildUrl($path, $clean_urls = NULL) { ...@@ -208,7 +209,7 @@ public function buildUrl($path, $clean_urls = NULL) {
$clean_urls = TRUE; $clean_urls = TRUE;
try { try {
$request = \Drupal::request(); $request = \Drupal::request();
$clean_urls = $request->attributes->get('clean_urls'); $clean_urls = RequestHelper::isCleanUrl($request);
} }
catch (ServiceNotFoundException $e) { catch (ServiceNotFoundException $e) {
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment