Commit deae32e9 authored by webchick's avatar webchick

Issue #1619446 by Niklas Fiekas: Fixed All autocomplete and...

Issue #1619446 by Niklas Fiekas: Fixed All autocomplete and drupal_json_output() responses are broken (returning Ajax instead of JSON).
parent 48a0b693
......@@ -5011,24 +5011,6 @@ function drupal_json_decode($var) {
return json_decode($var, TRUE);
}
/**
* Returns data in JSON format.
*
* This function should be used for JavaScript callback functions returning
* data in JSON format. It sets the header for JavaScript output.
*
* @param $var
* (optional) If set, the variable will be converted to JSON and output.
*/
function drupal_json_output($var = NULL) {
// We are returning JSON, so tell the browser.
drupal_add_http_header('Content-Type', 'application/json');
if (isset($var)) {
echo drupal_json_encode($var);
}
}
/**
* Gets a salt useful for hardening against SQL injection.
*
......
......@@ -7,6 +7,7 @@
use Drupal\entity\EntityFieldQuery;
use Drupal\Core\File\File;
use Symfony\Component\HttpFoundation\JsonResponse;
// Load all Field module hooks for File.
require_once DRUPAL_ROOT . '/core/modules/file/file.field.inc';
......@@ -318,7 +319,7 @@ function file_ajax_progress($key) {
}
}
drupal_json_output($progress);
return new JsonResponse($progress);
}
/**
......
......@@ -12,6 +12,7 @@
*/
use Drupal\node\Node;
use Symfony\Component\HttpFoundation\JsonResponse;
/**
* Maximum length of menu name as entered by the user. Database length is 32
......@@ -396,7 +397,7 @@ function menu_parent_options_js() {
}
$options = _menu_get_options(menu_get_menus(), $available_menus, array('mlid' => 0));
drupal_json_output($options);
return new JsonResponse($options);
}
/**
......
......@@ -5,6 +5,7 @@
* Admin page callbacks for the system module.
*/
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
......@@ -2206,7 +2207,7 @@ function system_add_date_format_type_form_submit($form, &$form_state) {
*/
function system_date_time_lookup() {
$result = format_date(REQUEST_TIME, 'custom', $_GET['format']);
drupal_json_output($result);
return new JsonResponse($result);
}
/**
......
......@@ -5,6 +5,7 @@
* Configuration system that lets administrators modify the workings of the site.
*/
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
/**
......@@ -3661,7 +3662,7 @@ function system_timezone($abbreviation = '', $offset = -1, $is_daylight_saving_t
// interpreted as the empty string.
$abbreviation = $abbreviation ? $abbreviation : '';
$timezone = timezone_name_from_abbr($abbreviation, intval($offset), $is_daylight_saving_time);
drupal_json_output($timezone);
return new JsonResponse($timezone);
}
/**
......
<?php
use Drupal\Core\Database\Query\AlterableInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
/**
* Implements hook_query_alter().
......@@ -84,11 +85,10 @@ function database_test_menu() {
*/
function database_test_db_query_temporary() {
$table_name = db_query_temporary('SELECT status FROM {system}', array());
drupal_json_output(array(
return new JsonResponse(array(
'table_name' => $table_name,
'row_count' => db_select($table_name)->countQuery()->execute()->fetchField(),
));
exit;
}
/**
......@@ -111,10 +111,9 @@ function database_test_even_pager_query($limit) {
$names = $query->execute()->fetchCol();
drupal_json_output(array(
return new JsonResponse(array(
'names' => $names,
));
exit;
}
/**
......@@ -137,10 +136,9 @@ function database_test_odd_pager_query($limit) {
$names = $query->execute()->fetchCol();
drupal_json_output(array(
return new JsonResponse(array(
'names' => $names,
));
exit;
}
/**
......@@ -168,10 +166,9 @@ function database_test_tablesort() {
// We need all the results at once to check the sort.
$tasks = $query->execute()->fetchAll();
drupal_json_output(array(
return new JsonResponse(array(
'tasks' => $tasks,
));
exit;
}
/**
......@@ -200,10 +197,9 @@ function database_test_tablesort_first() {
// We need all the results at once to check the sort.
$tasks = $query->execute()->fetchAll();
drupal_json_output(array(
return new JsonResponse(array(
'tasks' => $tasks,
));
exit;
}
/**
......
......@@ -280,7 +280,9 @@ function form_test_menu() {
* Form submit handler to return form values as JSON.
*/
function _form_test_submit_values_json($form, &$form_state) {
drupal_json_output($form_state['values']);
// 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']);
drupal_exit();
}
......@@ -996,7 +998,9 @@ function form_test_form_state_values_clean_form($form, &$form_state) {
*/
function form_test_form_state_values_clean_form_submit($form, &$form_state) {
form_state_values_clean($form_state);
drupal_json_output($form_state['values']);
// 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']);
exit;
}
......@@ -1098,7 +1102,9 @@ function _form_test_checkbox($form, &$form_state) {
* Return the form values via JSON.
*/
function _form_test_checkbox_submit($form, &$form_state) {
drupal_json_output($form_state['values']);
// 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']);
exit();
}
......@@ -1207,7 +1213,9 @@ function form_test_select($form, &$form_state) {
* Form submit handler for form_test_select().
*/
function form_test_select_submit($form, &$form_state) {
drupal_json_output($form_state['values']);
// 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']);
exit();
}
......@@ -1379,7 +1387,9 @@ function form_test_range($form, &$form_state) {
* Form submission handler for form_test_range().
*/
function form_test_range_submit($form, &$form_state) {
drupal_json_output($form_state['values']);
// 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']);
exit;
}
......@@ -1506,7 +1516,9 @@ function form_test_email($form, &$form_state) {
* Form submission handler for form_test_email().
*/
function form_test_email_submit($form, &$form_state) {
drupal_json_output($form_state['values']);
// 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']);
exit();
}
......@@ -1539,7 +1551,9 @@ function form_test_url($form, &$form_state) {
* Form submission handler for form_test_url().
*/
function form_test_url_submit($form, &$form_state) {
drupal_json_output($form_state['values']);
// 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']);
exit();
}
......@@ -1739,7 +1753,9 @@ function _form_test_disabled_elements($form, &$form_state) {
* Return the form values via JSON.
*/
function _form_test_disabled_elements_submit($form, &$form_state) {
drupal_json_output($form_state['values']);
// 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']);
exit();
}
......@@ -1768,7 +1784,9 @@ function _form_test_input_forgery($form, &$form_state) {
* Return the form values via JSON.
*/
function _form_test_input_forgery_submit($form, &$form_state) {
drupal_json_output($form_state['values']);
// 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']);
exit();
}
......
......@@ -200,8 +200,8 @@ function testNodeTermCreationAndDeletion() {
// Test autocomplete on term 3, which contains a comma.
// The term will be quoted, and the " will be encoded in unicode (\u0022).
$input = substr($term_objects['term3']->name, 0, 3);
$this->drupalGet('taxonomy/autocomplete/taxonomy_' . $this->vocabulary->machine_name . '/' . $input);
$this->assertRaw('{"\u0022' . $term_objects['term3']->name . '\u0022":"' . $term_objects['term3']->name . '"}', format_string('Autocomplete returns term %term_name after typing the first 3 letters.', array('%term_name' => $term_objects['term3']->name)));
$json = $this->drupalGet('taxonomy/autocomplete/taxonomy_' . $this->vocabulary->machine_name . '/' . $input);
$this->assertEqual($json, '{"\u0022' . $term_objects['term3']->name . '\u0022":"' . $term_objects['term3']->name . '"}', format_string('Autocomplete returns term %term_name after typing the first 3 letters.', array('%term_name' => $term_objects['term3']->name)));
// Test autocomplete on term 4 - it is alphanumeric only, so no extra
// quoting.
......
......@@ -7,6 +7,7 @@
use Drupal\taxonomy\Term;
use Drupal\taxonomy\Vocabulary;
use Symfony\Component\HttpFoundation\JsonResponse;
/**
* Menu callback; displays all nodes associated with a term.
......@@ -166,5 +167,5 @@ function taxonomy_autocomplete($field_name, $tags_typed = '') {
}
}
drupal_json_output($term_matches);
return new JsonResponse($term_matches);
}
......@@ -5,6 +5,7 @@
* User page callback file for the user module.
*/
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
/**
......@@ -19,7 +20,7 @@ function user_autocomplete($string = '') {
}
}
drupal_json_output($matches);
return new JsonResponse($matches);
}
/**
......
......@@ -513,24 +513,6 @@
*/
# drupal_fast_404();
/**
* External access proxy settings:
*
* If your site must access the Internet via a web proxy then you can enter
* the proxy settings here. Currently only basic authentication is supported
* by using the username and password variables. The proxy_user_agent variable
* can be set to NULL for proxies that require no User-Agent header or to a
* non-empty string for proxies that limit requests to a specific agent. The
* proxy_exceptions variable is an array of host names to be accessed directly,
* not via proxy.
*/
# $conf['proxy_server'] = '';
# $conf['proxy_port'] = 8080;
# $conf['proxy_username'] = '';
# $conf['proxy_password'] = '';
# $conf['proxy_user_agent'] = '';
# $conf['proxy_exceptions'] = array('127.0.0.1', 'localhost');
/**
* Authorized file system operations:
*
......
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