The following functions are deprecated, all calls should be replaced with direct calls to the methods specified in their docblocks:

drupal_http_build_query()
drupal_parse_url()
drupal_encode_path()
_external_url_is_local()
valid_url()
url_is_external()

The following functions are also due to be removed, but have complications so should be dealt with in followups:

drupal_get_query_parameters()
check_url()

Comments

ianthomas_uk’s picture

Title: Remove uses of deprecated drupal_http_build_query() » Remove uses of deprecated URL functions
Issue summary: View changes
ianthomas_uk’s picture

Issue summary: View changes

Some of these still need to be marked @deprecated, I plan to open a separate issue for that.

grom358’s picture

Status: Active » Needs review
StatusFileSize
new33.66 KB

Using Function Replacer Part of Write script to automate replacement of deprecated functions where possible.

I made some manual changes to UrlHelper (change so query parameter is optional for filterQueryParameters and added checkUrl class method). Then applied the following commands.

~/d8codetools/function_replace.php drupal_get_query_parameters 'Drupal\Component\Utility\UrlHelper' UtilityUrlHelper filterQueryParameters
~/d8codetools/function_replace.php drupal_http_build_query 'Drupal\Component\Utility\UrlHelper' UtilityUrlHelper buildQuery
~/d8codetools/function_replace.php drupal_parse_url 'Drupal\Component\Utility\UrlHelper' UtilityUrlHelper parse
~/d8codetools/function_replace.php drupal_encode_path 'Drupal\Component\Utility\UrlHelper' UtilityUrlHelper encodePath
~/d8codetools/function_replace.php _external_url_is_local 'Drupal\Component\Utility\UrlHelper' UtilityUrlHelper externalIsLocal
~/d8codetools/function_replace.php valid_url 'Drupal\Component\Utility\UrlHelper' UtilityUrlHelper isValid
~/d8codetools/function_replace.php check_url 'Drupal\Component\Utility\UrlHelper' UtilityUrlHelper checkUrl
~/d8codetools/function_replace.php url_is_external 'Drupal\Component\Utility\UrlHelper' UtilityUrlHelper isExternal
ianthomas_uk’s picture

Issue summary: View changes
Status: Needs review » Needs work
+++ b/core/lib/Drupal/Component/Utility/UrlHelper.php
@@ -82,7 +83,10 @@ public static function buildQuery(array $query, $parent = '') {
-  public static function filterQueryParameters(array $query, array $exclude = array(), $parent = '') {
+  public static function filterQueryParameters(array $query = NULL, array $exclude = array(), $parent = '') {
+    if (!isset($query)) {
+      $query = \Drupal::request()->query->all();
+    }

We shouldn't call \Drupal from OO code - dependencies should be injected so they can be tested, calling \Drupal makes this method silently depend on the Request object.

Instead, we should correct any places that are currently not passing $query and ensure they do. I suggest we split that off into it's own issue so as not to delay conversion of the other functions.

~/d8codetools/function_replace.php check_url 'Drupal\Component\Utility\UrlHelper' UtilityUrlHelper checkUrl

There is no 'checkUrl' function on UrlHelper. This actually wraps two functions, String::checkPlain(UrlHelper::stripDangerousProtocols($uri));. Again, let's leave this for now.

New function replace commands:

~/d8codetools/function_replace.php drupal_http_build_query 'Drupal\Component\Utility\UrlHelper' UtilityUrlHelper buildQuery
~/d8codetools/function_replace.php drupal_parse_url 'Drupal\Component\Utility\UrlHelper' UtilityUrlHelper parse
~/d8codetools/function_replace.php drupal_encode_path 'Drupal\Component\Utility\UrlHelper' UtilityUrlHelper encodePath
~/d8codetools/function_replace.php _external_url_is_local 'Drupal\Component\Utility\UrlHelper' UtilityUrlHelper externalIsLocal
~/d8codetools/function_replace.php valid_url 'Drupal\Component\Utility\UrlHelper' UtilityUrlHelper isValid
~/d8codetools/function_replace.php url_is_external 'Drupal\Component\Utility\UrlHelper' UtilityUrlHelper isExternal

I've reviewed the other commands, and they are good.

grom358’s picture

Status: Needs work » Needs review
StatusFileSize
new14.17 KB
ianthomas_uk’s picture

StatusFileSize
new2.31 KB
new15.7 KB

That patch looks good, except for a couple of comments / test messages that weren't updated, but it catches everything else correctly.

Here's a patch with those small changes.

longwave’s picture

Status: Needs review » Reviewed & tested by the community

Looks good, only the function declarations remain, plus one self-referential comment to drupal_parse_url() that will be removed when the function itself is removed.

alexpott’s picture

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

2221695-6-url.patch no longer applies.

error: patch failed: core/includes/file.inc:5
error: core/includes/file.inc: patch does not apply
error: patch failed: core/lib/Drupal/Core/StreamWrapper/PublicStream.php:7
error: core/lib/Drupal/Core/StreamWrapper/PublicStream.php: patch does not apply

ianthomas_uk’s picture

I have spoken to webchick and she suggested that she would be available to review/commit this next Monday, 31st March. There's little point in rerolling the patch until the weekend, but if there's a patch here on Monday that applies then I'll review it.

saltednut’s picture

Status: Needs work » Needs review
StatusFileSize
new0 bytes

Straight reroll.

saltednut’s picture

StatusFileSize
new15.63 KB

Ugh.. patching error. Here's the correct one.

saltednut’s picture

StatusFileSize
new2.64 KB
ianthomas_uk’s picture

Status: Needs review » Reviewed & tested by the community

Looks good. I've confirmed #11 is a good reroll of #6, which was RTBC.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 11: 2221695-11-url.patch, failed testing.

ianthomas_uk’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs reroll
StatusFileSize
new15.67 KB

Simple reroll, just conflicting context in the use statements. Diffing this against #11 shows no other changes.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 15: 2221695-15-url.patch, failed testing.

Jalandhar’s picture

Status: Needs work » Needs review
StatusFileSize
new15.68 KB

Updating the patch with reroll. Please review.

ParisLiakos’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new15.68 KB
new1.6 KB

patch looks ready to me..i only found two really minor nitpicks (full namespace not starting with \ in comments) but i fixed it myself.

i grepped core and no calls to those functions remain

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.x, thanks!

  • Commit 1756114 on 8.x by catch:
    Issue #2221695 by brantwynn, ianthomas_uk, grom358, ParisLiakos,...

Status: Fixed » Closed (fixed)

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