Problem/Motivation

There is a call to request_uri() inside FormBuilder. It should be possible to directly replace this with $request->getRequestUri()

Proposed resolution

Remaining tasks

User interface changes

API changes

Comments

martin107’s picture

Assigned: Unassigned » martin107

I am working on this now...

martin107’s picture

Status: Active » Needs review
StatusFileSize
new14.48 KB

Firstly- This is a first iteration. One unit test is failing and I am open to other ways forward.

There are 2 highly specialize calls to request_uri(TRUE), both called before the container and the request stack are available.
I have chosen to simplify the logic in request_uri for those function calls and place them in a new function request_uri_without_query_string().

I think that is an acceptable compromise, but hey that needs review.

Second - The following objects expect extra parameter in their constructors.

core/modules/locale/src/LocaleLookup.php - now requires a $request_uri string
core/modules/locale/src/LocaleTranslation.php - now requires a RequestStack object

This at first may look funny... I have followed the Law of Demeter, LocaleLookup only uses a string $request_uri and so I did not want to pass in a RequestStack object just so it could "reach through the parameter" to get what is actually wanted.

Thirdly

this from LocaleLookup.php

  /**
   * Wraps request_uri().
   */
  protected function requestUri($omit_query_string = FALSE) {
    return request_uri($omit_query_string);
  }

So this class was providing it own version of a wrapper used only once .. in short it can now be rationalized away..

Lastly @dawehner, can I confirm what I think you are thinking....

So the line is at this stage of the release cycle is :-

Change to core/modules/locale/locale.services.yml are a minor API change with limited impact to the rest of the system or contrib and are therefore acceptable?

I will try and finish this off tonight...

Status: Needs review » Needs work

The last submitted patch, 2: request-2372763-2.patch, failed testing.

martin107’s picture

Status: Needs work » Needs review
StatusFileSize
new2.23 KB

I have backouted out 85% of my changes.

LocaleLocaleLookupTest is failing a circular dependency test.

I have this quote from the constructor of \Drupal\early_translation_test\Auth

    // Authentication providers are called early during in the bootstrap.
    // Getting the user storage used to result in a circular reference since
    // translation involves a call to \Drupal\locale\LocaleLookup that tries to
    // get the user roles.
    // @see https://drupal.org/node/2241461

So using similar arguments a Request cannot be injected into LocaleLookup because
of the whole bootstrap thing... Ah so you live and learn :)

Also, request_uri_without_query_string() has been reverted back to request_uri()
I was being too clever and it doesn't work in the general case.

Other test are still failing ... but I will look more soon.

( The interdiff is not helpful in this instance and anyway the patch is small. )

Status: Needs review » Needs work

The last submitted patch, 4: request-2372763-4.patch, failed testing.

martin107’s picture

Status: Needs work » Needs review
StatusFileSize
new2.23 KB
new710 bytes

Trivial fixup of DblogTest

Status: Needs review » Needs work

The last submitted patch, 6: request-2372763-6.patch, failed testing.

martin107’s picture

Assigned: martin107 » Unassigned
Status: Needs work » Needs review
StatusFileSize
new3.12 KB
new1.92 KB

A) Corrected mistake in annotation.
B) Removed function making a single called to another function. ( And the function overriding it for testing. )

Looking at failing test, which is due to this new call to getRequestUri()
in FormBuilder::prepareForm()

    // Only update the action if it is not already set.
    if (!isset($form['#action'])) {
      $form['#action'] = $this->requestStack->getCurrentRequest()->getRequestUri();
    }

$form['#action'] is set to "/batch?id=6&op=do_nojs&op=do"

I will have more time to look at this on Sunday

Status: Needs review » Needs work

The last submitted patch, 8: request-2372763-8.patch, failed testing.

sonu.raj.chauhan’s picture

StatusFileSize
new1.44 KB
sonu.raj.chauhan’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 10: request-2372763-10.patch, failed testing.

dawehner’s picture

+++ b/core/lib/Drupal/Core/Form/FormBuilder.php
@@ -301,7 +301,7 @@ public function rebuildForm($form_id, FormStateInterface &$form_state, $old_form
+    // #action defaults to $this->requestStack->getCurrentRequest()->getRequestUri();, but in case of Ajax and other partial

I guess we need to linebreak this :)

sonu.raj.chauhan’s picture

Status: Needs work » Needs review
StatusFileSize
new1.2 KB
sonu.raj.chauhan’s picture

StatusFileSize
new1.2 KB

The last submitted patch, 14: request-2372763-14.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 15: request-2372763-15.patch, failed testing.

diego21’s picture

Assigned: Unassigned » diego21

Working on this issue now.

Status: Needs work » Needs review

mhamed queued 15: request-2372763-15.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 15: request-2372763-15.patch, failed testing.

diego21’s picture

Assigned: diego21 » Unassigned
keopx’s picture

Status: Needs work » Needs review
StatusFileSize
new1.2 KB

re-roll

Status: Needs review » Needs work

The last submitted patch, 22: request-2372763-22.patch, failed testing.

segi’s picture

Assigned: Unassigned » segi
Issue tags: +SprintWeekend2015
segi’s picture

Assigned: segi » Unassigned

Status: Needs work » Needs review

keopx queued 22: request-2372763-22.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 22: request-2372763-22.patch, failed testing.

keopx’s picture

Status: Needs work » Needs review
StatusFileSize
new1.65 KB
new6.45 KB
new6.91 KB

Rerrol patch based on #8 because y newed versions didnt appeared some changes.

Status: Needs review » Needs work

The last submitted patch, 28: request-2372763-28.patch, failed testing.

Status: Needs work » Needs review

diego21 queued 28: request-2372763-28.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 28: request-2372763-28.patch, failed testing.

diego21’s picture

Status: Needs work » Reviewed & tested by the community
diego21’s picture

It works for me.

diego21’s picture

Status: Reviewed & tested by the community » Needs work

Sorry for changing the status, it was a mistake.

Status: Needs work » Needs review

Saphyel queued 28: request-2372763-28.patch for re-testing.

penyaskito’s picture

Status: Needs review » Needs work

@keopx Thanks for working on this!

Some remarks.

  1. +++ b/core/includes/bootstrap.inc
    @@ -598,6 +598,12 @@ function drupal_validate_utf8($text) {
    + * NB This function is intended for limited use, in cases before the $container
    

    Does NB mean nota bene? Should be clarified. It is not common to use abbreviations in code comments.

  2. +++ b/core/includes/bootstrap.inc
    @@ -598,6 +598,12 @@ function drupal_validate_utf8($text) {
    + * is available. Use $request->getRequestUri() whereever possible.
    

    Whereever typo, should be wherever.

  3. +++ b/core/lib/Drupal/Core/DrupalKernel.php
    @@ -866,10 +866,10 @@ protected function initializeRequestGlobals(Request $request) {
    +        // $request->getRequestUri() returns a URI with the script name, resulting in
    
    +++ b/core/lib/Drupal/Core/Form/FormBuilder.php
    @@ -301,7 +301,7 @@ public function rebuildForm($form_id, FormStateInterface &$form_state, $old_form
    +    // #action defaults to $request->getRequestUri(), but in case of Ajax and other partial
    

    These comment lines exceed 80 chars. We need to re-wrap them.

The last submitted patch, 28: request-2372763-28.patch, failed testing.

nlisgo’s picture

Status: Needs work » Needs review
StatusFileSize
new6.81 KB
new2.07 KB

I've addressed remarks in #36.

I've removed the NB comment and wondered if it should be instead tagged as deprecated?

Status: Needs review » Needs work

The last submitted patch, 38: replace_request_uri-2372763-38.patch, failed testing.

dawehner’s picture

Status: Needs work » Reviewed & tested by the community

Totally forgot about this issue but #2426489: Remove request_uri() does the same and is RTBC :(

nlisgo’s picture

@dawehner This issue should be closed now right and marked as duplicate?

nlisgo’s picture

Status: Reviewed & tested by the community » Closed (duplicate)

Issue #2426489: Remove request_uri() was created after this issue but had progressed to RTBC before this issue was noticed.