Commit 6383d18e authored by alexpott's avatar alexpott
Browse files

Issue #2093161 by rbayliss, haithem_pro, sandipmkhairnar, InternetDevels,...

Issue #2093161 by rbayliss, haithem_pro, sandipmkhairnar, InternetDevels, longwave, idflood, Sumeet.Pareek, sidharthap, xeniak, ianthomas_uk: Remove all calls to drupal_json_encode() in favour of \Drupal\Component\Utility\Json::encode().
parent 98487628
......@@ -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);
}
/**
......
......@@ -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) {
......
......@@ -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;
......
......@@ -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)),
)
)
);
......
......@@ -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.');
}
}
......@@ -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;
}
......
......@@ -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.');
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment