Come together with the global Drupal community in Rotterdam, 28 Sept – 1 Oct 2026. Sessions, contribution, connection, and Early Bird savings until 8 June.
The common.inc file contains the
function drupal_json_encode($var) {
return Json::encode($var);
}
so we need to use directly \Drupal\Component\Utility\Json::encode() and remove this function "drupal_json_encode" from common.inc file ?
There is a discussion going on https://drupal.org/node/2093143
@sandipmkhairnar, if you don't put use \Drupal\Component\Utility\Json at the top of the files where you want to call Json::encode() then PHP won't know what to do.
Reroll, plus add @ingroup php_wrappers back to Json::decode. That was removed in #34, but I don't understand why (it's still a wrapper around a PHP function, even if it isn't called drupal_$foo any more).
Other than that the patch looks good and should be an easy review, so it would be good to get this to RTBC.
error: patch failed: core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php:8
error: core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php: patch does not apply
I just dont see the point of removing usage but not functions that are already deprecated for months now.
We will have to remove them anyway and not doing it here means more issues + more maintainers and reviewers time.
But i hate coming here so late and re-scoping the issue, so i ll let a maintainer decide what would be best
Comments
Comment #1
xeniak commentedOK, did it. This is my first patch; so please let me know if I did anything wrong.
Issue #2093161 by thedavidmeister: Remove and deprecate all calls to drupal_json_encode() in favour of \Drupal\Component\Utility\Json::encode().
Comment #3
thedavidmeister commentedHey, thanks for the patch. Aside from the fails that you can see from the testbot, I don't think this stuff should be in the patch.
Comment #4
sidharthapThe common.inc file contains the
function drupal_json_encode($var) {
return Json::encode($var);
}
so we need to use directly \Drupal\Component\Utility\Json::encode() and remove this function "drupal_json_encode" from common.inc file ?
There is a discussion going on https://drupal.org/node/2093143
Comment #5
sandipmkhairnar commentedComment #6
sandipmkhairnar commentedComment #7
xeniak commentedYeah, I'm not sure what that is - I think it's something Zend Studio adds. I'll have to investigate how to get it excluded from the patch.
Comment #8
sandipmkhairnar commentedThanks @xeniak for comment. Not sure but, I think it is removing all deprecate all calls drupal_json_encode() to json_encode.
Comment #10
sandipmkhairnar commentedComment #12
xeniak commentedComment #13
thedavidmeister commenteddrupal_json_encode() is *already deprecated*.
https://api.drupal.org/api/drupal/core%21includes%21common.inc/function/...
Comment #14
thedavidmeister commented@sandipmkhairnar, if you don't put
use \Drupal\Component\Utility\Jsonat the top of the files where you want to callJson::encode()then PHP won't know what to do.http://www.php.net/manual/en/language.namespaces.rationale.php
http://www.php.net/manual/en/language.namespaces.importing.php
+ $element['#value'] = 'var drupalSettings = ' . json::encode(drupal_merge_js_settings($js_asset['data'])) . ";";return json::encode($commands);Json, not json.
Comment #15
rbayliss commentedAdded those use statements and corrected the capitalization of the class name.
Comment #17
rbayliss commentedLet's try this again... Same patch, hopefully better formatting.
Comment #18
thedavidmeister commentedI applied this patch.
Code standards look fine.
Site installs and clicking around a bit produces no fatal errors.
Didn't find any more calls to drupal_json_encode() after applying the patch.
The remaining docs references to drupal_json_encode() are probably fine as they're only on drupal_json_decode() and Json::decode().
RTBC.
I'd like to use this review as bonus (#2094585: [policy, no patch] Core review bonus) for #1987396: Refactor & Clean-up comment.module theme functions.
Comment #19
alexpottPatch no longer applies.
Comment #20
sidharthapThere are some occurrence of json_encode() in vendor/* directory. Will it required an attention too with this patch.
Comment #21
mcrittenden commentedTags
Comment #22
areke commentedThe patch no longer applies; it needs to be re-rolled again.
Comment #23
sumeet.pareek commentedHere is a re-rolled version of the patch.
Comment #25
haithem_pro commentedstart working on issue
Comment #26
haithem_pro commentedComment #27
haithem_pro commentedComment #29
damiankloip commented27: remove_calls_drupal_json_encode-2093161-26.patch queued for re-testing.
Comment #34
internetdevels commentedComment #35
sunComment #36
idflood commentedPatch in #34 wasn't applying anymore so here is a reroll.
Comment #37
ianthomas_ukReroll, plus add @ingroup php_wrappers back to Json::decode. That was removed in #34, but I don't understand why (it's still a wrapper around a PHP function, even if it isn't called drupal_$foo any more).
Other than that the patch looks good and should be an easy review, so it would be good to get this to RTBC.
Comment #38
thedavidmeister commented#2094585: [policy, no patch] Core review bonus from https://drupal.org/comment/8464143#comment-8464143
Comment #39
ParisLiakos commentedShouldn't we also remove the function here?
Comment #40
longwaveRerolled.
Not sure we should remove drupal_json_encode() while its companion function drupal_json_decode() still exists?
Comment #41
ParisLiakos commentedThey are different functions and there is already a similar issue #2093173: Remove all calls to drupal_json_decode(), use \Drupal\Component\Utility\Json::decode()
I just dont see the point of removing usage but not functions that are already deprecated for months now.
We will have to remove them anyway and not doing it here means more issues + more maintainers and reviewers time.
But i hate coming here so late and re-scoping the issue, so i ll let a maintainer decide what would be best
Comment #42
alexpottCommitted 6383d18 and pushed to 8.x. Thanks!
Comment #43
alexpottYep all usages should be removed before the function. Less to revert if removing the function falls or breaks something unexpectedly.
Comment #44
ParisLiakos commentedah, i see, that makes sense:)
Thanks!