Problem/Motivation

We have removed almost all old functions like current_path(), request_path() etc.
request_uri is still there, even we have perfect replacements since always on the $request object

Proposed resolution

Let's replace it and remove request_uri

Remaining tasks

User interface changes

API changes

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Task: Part of cleaning up bootstrap.inc from not needed stuff.
Issue priority Normal, because the impact is low
Disruption Really small disruption, especially because we already have a recommended other API people should use.

Comments

dawehner’s picture

Status: Active » Needs review
StatusFileSize
new15.92 KB

Let's see ...

This will need a reroll after #2426457: Remove request_path

dawehner’s picture

https://www.drupal.org/node/2382211 will need an update once this is in.

Status: Needs review » Needs work

The last submitted patch, 1: 2426489-1.patch, failed testing.

dawehner’s picture

Status: Needs work » Postponed

.

dawehner’s picture

Status: Postponed » Needs review
StatusFileSize
new16.32 KB
new1.03 KB

Reroll + fixes.

Status: Needs review » Needs work

The last submitted patch, 5: 2426489-5.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new16.32 KB
new678 bytes

There we go.

dawehner’s picture

Assigned: dawehner » Unassigned

.

dawehner’s picture

Issue summary: View changes

Worked on the issue summary / beta evaluation.

Crell’s picture

Status: Needs review » Needs work
  1. +++ b/core/lib/Drupal/Core/DrupalKernel.php
    @@ -872,7 +872,7 @@ protected function initializeRequestGlobals(Request $request) {
             // request_uri() returns a URI with the script name, resulting in
             // non-clean URLs unless
             // there's other code that intervenes.
    -        if (strpos(request_uri(TRUE) . '/', $base_path . $script_path) !== 0) {
    +        if (strpos($request->getPathInfo() . '/', $base_path . $script_path) !== 0) {
    

    Remove or update the comment too, please.

  2. +++ b/core/lib/Drupal/Core/Form/FormBuilder.php
    @@ -301,9 +301,9 @@ public function rebuildForm($form_id, FormStateInterface &$form_state, $old_form
    +    // #action defaults to $reuqest->getRequestUri(), but in case of Ajax and
    +    // other partial rebuilds, the form is submitted to an alternate URL, and
    +    // the original #action needs to be retained.
    

    $reuqest? :-)

  3. +++ b/core/modules/dblog/src/Tests/DbLogTest.php
    @@ -147,7 +147,7 @@ private function generateLogEntries($count, $type = 'custom', $severity = RfcLog
    -      'request_uri' => $base_root . request_uri(),
    +      'request_uri' => $base_root . \Drupal::request()->getRequestUri(),
    

    This in a test seems spurious to me. Tests should be request-agnostic, or able to be. In a test, why don't we just hard-code a request uri for testing purposes? That would be more stable and predictable and less prone to random weirdness.

  4. +++ b/core/modules/locale/src/LocaleLookup.php
    @@ -95,6 +105,7 @@ public function __construct($langcode, $context, StringStorageInterface $string_
    @@ -142,7 +153,7 @@ protected function resolveCacheMiss($offset) {
    
    @@ -142,7 +153,7 @@ protected function resolveCacheMiss($offset) {
             'source' => $offset,
             'context' => $this->context,
             'version' => \Drupal::VERSION,
    -      ))->addLocation('path', $this->requestUri())->save();
    +      ))->addLocation('path', $this->requestStack->getCurrentRequest()->getRequestUri())->save();
           $value = TRUE;
         }
     
    @@ -177,11 +188,4 @@ protected function resolveCacheMiss($offset) {
    
    @@ -177,11 +188,4 @@ protected function resolveCacheMiss($offset) {
         return $value;
       }
     
    -  /**
    -   * Wraps request_uri().
    -   */
    -  protected function requestUri($omit_query_string = FALSE) {
    -    return request_uri($omit_query_string);
    -  }
    

    Technically we could leave the method in place, just change what it's wrapping. I'm fine either way.

We need a beta eval here, but I am +1 on allowing it.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new16.6 KB
new2.78 KB

$reuqest? :-)

Just imagine how hard it was to type it, given that you type $request all day long.

This in a test seems spurious to me. Tests should be request-agnostic, or able to be. In a test, why don't we just hard-code a request uri for testing purposes? That would be more stable and predictable and less prone to random weirdness.

Well, I think that is out of scope to change, but well, here it is.

Technically we could leave the method in place, just change what it's wrapping. I'm fine either way.

I see no reason to keep it.

We need a beta eval here, but I am +1 on allowing it.

... An additional one to the existing one?

Status: Needs review » Needs work

The last submitted patch, 11: 2426489-11.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new16.66 KB
new1.13 KB

@crell
I'm sorry but if you really want to fix it, feel free to open up a follow up :p

kgoel’s picture

some nitpicks

 ->setConstructorArgs(array('en', 'irrelevant', $this->storage, $this->cache, $this->lock, $this->configFactory, $this->languageManager, $this->requestStack))
      ->setMethods(array('persist'))

Should it have getRequestUri for setMethods?

use Drupal\Core\PageCache\RequestPolicyInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Composer\Autoload\ClassLoader;

While you are at it, some unused classes in DrupalKernel.php

use Drupal\Component\Datetime\DateTimePlus;
use Drupal\Component\Utility\Environment;
use Symfony\Component\ClassLoader\ApcClassLoader;
use Symfony\Component\HttpFoundation\Response;

some unused classes in bootstrap.inc

dawehner’s picture

@kgoel
You don't use dreditor? This sounds like you would not slack at all ;)

Should it have getRequestUri for setMethods?

We removed the getRequestUri method in this patch, so we can no longer mock that method.

While you are at it, some unused classes in DrupalKernel.php

some unused classes in bootstrap.inc

Mh, I still think we should not break other patches due to out of scope changes in this issue, so sorry I won't change that.

dawehner’s picture

@kgoel
Do you have some additional points or do you think this issue is RTBC?

kgoel’s picture

Status: Needs review » Reviewed & tested by the community

@dawehner -
I do use dreditor :)

We removed the getRequestUri method in this patch, so we can no longer mock that method.

I think you meant request_uri() removed from this patch

Mh, I still think we should not break other patches due to out of scope changes in this issue, so sorry I won't change that.

Maybe I need to change as how I review patches.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs change record

We need a change record for this. I consider this change a followup of the numerous criticals to remove Drupal's dependence on $_SERVER and use the symfony request object everywhere.

dawehner’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs change record
alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed d742115 and pushed to 8.0.x. Thanks!

Thanks for adding the beta evaluation to the issue summary. I agree that removing this is inline with moving to Symfony's request processing system and this issue should be considered a followup to that work.

  • alexpott committed d742115 on 8.0.x
    Issue #2426489 by dawehner: Remove request_uri()
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

David_Rothstein’s picture

-  // Prevent multiple slashes to avoid cross site requests via the Form API.
-  $uri = '/' . ltrim($uri, '/');

Removing that is problematic - see linked issue.