diff --git a/core/includes/ajax.inc b/core/includes/ajax.inc index 7bb41083cba7f73581b172527c539304e8efe027..e11d366b777ea74a8a6ce2a49cb78b7a53e3bc28 100644 --- a/core/includes/ajax.inc +++ b/core/includes/ajax.inc @@ -5,6 +5,8 @@ * Functions for use with Drupal's Ajax framework. */ +use Drupal\Component\Utility\Json; + /** * @defgroup ajax Ajax framework * @{ @@ -300,7 +302,7 @@ function ajax_render($commands = array()) { // Allow modules to alter any Ajax response. drupal_alter('ajax_render', $commands); - return drupal_json_encode($commands); + return Json::encode($commands); } /** diff --git a/core/lib/Drupal/Component/Utility/Json.php b/core/lib/Drupal/Component/Utility/Json.php index 54614b5371001f53c1e1069c7fd4bd5b132a9e91..88e55aed192d0b1ceb9a8d4eb870b9d56658fafa 100644 --- a/core/lib/Drupal/Component/Utility/Json.php +++ b/core/lib/Drupal/Component/Utility/Json.php @@ -40,7 +40,6 @@ public static function encode($variable) { * @return mixed * Returns the decoded string. * - * @see drupal_json_encode() * @ingroup php_wrappers */ public static function decode($string) { diff --git a/core/lib/Drupal/Core/Asset/JsCollectionRenderer.php b/core/lib/Drupal/Core/Asset/JsCollectionRenderer.php index 5f920d48450ce907c45be1b33248bbc1057e3899..cdaf1d8288ab467c93cc11f23929c6b9eaa77887 100644 --- a/core/lib/Drupal/Core/Asset/JsCollectionRenderer.php +++ b/core/lib/Drupal/Core/Asset/JsCollectionRenderer.php @@ -7,6 +7,7 @@ namespace Drupal\Core\Asset; use Drupal\Core\KeyValueStore\StateInterface; +use Drupal\Component\Utility\Json; /** * Renders JavaScript assets. @@ -67,7 +68,7 @@ public function render(array $js_assets) { switch ($js_asset['type']) { case 'setting': $element['#value_prefix'] = $embed_prefix; - $element['#value'] = 'var drupalSettings = ' . drupal_json_encode(drupal_merge_js_settings($js_asset['data'])) . ";"; + $element['#value'] = 'var drupalSettings = ' . Json::encode(drupal_merge_js_settings($js_asset['data'])) . ";"; $element['#value_suffix'] = $embed_suffix; break; diff --git a/core/modules/contextual/lib/Drupal/contextual/Plugin/views/field/ContextualLinks.php b/core/modules/contextual/lib/Drupal/contextual/Plugin/views/field/ContextualLinks.php index 7a40df1c544540254347eea0378c2cb9a596fca1..2f6004ab3c84f67d5957d81cc6bce6e6ce7b8152 100644 --- a/core/modules/contextual/lib/Drupal/contextual/Plugin/views/field/ContextualLinks.php +++ b/core/modules/contextual/lib/Drupal/contextual/Plugin/views/field/ContextualLinks.php @@ -9,6 +9,7 @@ use Drupal\views\Plugin\views\field\FieldPluginBase; use Drupal\views\ResultRow; +use Drupal\Component\Utility\Json; /** * Provides a handler that adds contextual links. @@ -114,7 +115,7 @@ public function render(ResultRow $values) { '', array(), array( - 'contextual-views-field-links' => drupal_encode_path(drupal_json_encode($links)), + 'contextual-views-field-links' => drupal_encode_path(Json::encode($links)), ) ) ); diff --git a/core/modules/editor/lib/Drupal/editor/Tests/EditIntegrationTest.php b/core/modules/editor/lib/Drupal/editor/Tests/EditIntegrationTest.php index 62973adfe78e3d291b03ecdac6690f5fca133b23..de4f1fccdae724b0f1b0faa78d08cee4104f96f7 100644 --- a/core/modules/editor/lib/Drupal/editor/Tests/EditIntegrationTest.php +++ b/core/modules/editor/lib/Drupal/editor/Tests/EditIntegrationTest.php @@ -7,6 +7,7 @@ namespace Drupal\editor\Tests; +use Drupal\Component\Utility\Json; use Drupal\Core\Language\Language; use Drupal\edit\EditorSelector; use Drupal\edit\MetadataGenerator; @@ -199,7 +200,7 @@ public function testGetUntransformedTextCommand() { 'data' => 'Test', ) ); - $this->assertEqual(drupal_json_encode($expected), $response->prepare($request)->getContent(), 'The GetUntransformedTextCommand AJAX command works correctly.'); + $this->assertEqual(Json::encode($expected), $response->prepare($request)->getContent(), 'The GetUntransformedTextCommand AJAX command works correctly.'); } } diff --git a/core/modules/system/tests/modules/form_test/form_test.module b/core/modules/system/tests/modules/form_test/form_test.module index c176144d599299d076b9a3392c83b4d626db003d..0e8bdb9581ed62c18aed509b379eaae822bcef26 100644 --- a/core/modules/system/tests/modules/form_test/form_test.module +++ b/core/modules/system/tests/modules/form_test/form_test.module @@ -5,6 +5,7 @@ * Helper module for the form API tests. */ +use Drupal\Component\Utility\Json; use Drupal\Core\Database\Connection; use Drupal\Core\Database\Database; use Drupal\Core\Language\Language; @@ -767,7 +768,7 @@ function form_test_form_state_values_clean_form_submit($form, &$form_state) { form_state_values_clean($form_state); // This won't have a proper JSON header, but Drupal doesn't check for that // anyway so this is fine until it's replaced with a JsonResponse. - print drupal_json_encode($form_state['values']); + print Json::encode($form_state['values']); exit; } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php index ea316af4d587edf3e19e7430f20f049f42c1b9a6..a84f4009e22ae93977f91886c4d1f7f36e502bfd 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php @@ -7,6 +7,7 @@ namespace Drupal\taxonomy\Tests; +use Drupal\Component\Utility\Json; use Drupal\Component\Utility\Tags; use Drupal\Core\Field\FieldDefinitionInterface; @@ -274,7 +275,7 @@ function testTermAutocompletion() { 'value' => check_plain($first_term->label()), 'label' => $first_term->label(), )); - $this->assertRaw(drupal_json_encode($target), 'Autocomplete returns only the expected matching term.'); + $this->assertRaw(Json::encode($target), 'Autocomplete returns only the expected matching term.'); // Try to autocomplete a term name with both a comma and a slash. $input = '"term with, comma and / a'; @@ -286,7 +287,7 @@ function testTermAutocompletion() { 'value' => $n, 'label' => check_plain($third_term->label()), )); - $this->assertRaw(drupal_json_encode($target), 'Autocomplete returns a term containing a comma and a slash.'); + $this->assertRaw(Json::encode($target), 'Autocomplete returns a term containing a comma and a slash.'); } /**