function _wysiwyg_settings_form_validate_json_object in Wysiwyg 7.2
Same name and namespace in other branches
- 6.2 wysiwyg.admin.inc \_wysiwyg_settings_form_validate_json_object()
Validation helper for JSON based elements.
Ensures double quotes are used around property names and values.
Parameters
$element: The form element with a '#value' property to validate.
$form_state: The form state to update with the processed value.
3 calls to _wysiwyg_settings_form_validate_json_object()
- wysiwyg_tinymce_settings_form_validate_menu in editors/
tinymce.inc - #element_validate handler for menu element added by wysiwyg_tinymce_settings_form().
- _wysiwyg_tinymce_settings_form_validate_formats in editors/
tinymce.inc - #element_validate handler for formats element added by wysiwyg_tinymce_settings_form().
- _wysiwyg_tinymce_settings_form_validate_style_formats in editors/
tinymce.inc - #element_validate handler for style_formats element added by wysiwyg_tinymce_settings_form().
File
- ./
wysiwyg.admin.inc, line 468 - Integrate Wysiwyg editors into Drupal.
Code
function _wysiwyg_settings_form_validate_json_object($element, &$form_state) {
$ret = array(
'valid' => TRUE,
);
if (!empty($element['#value'])) {
$value = $element['#value'];
// Ensure double quotes are used around property names.
$value = preg_replace('/(?<=^|,|\\n|{)(\\s*)(\'?)(\\w+)\\2\\s*:/', '$1"$3":', $value);
// Ensure double quotes are used around string values.
$value = preg_replace('/(?<=^|,|\\n|{)\\s*"(\\w+)"\\s*:\\s*\'(.*?)\'\\s*(?=$|\\n|,|})/', '"$1":"$2"', $value);
$ret['processed value'] = $value;
form_set_value($element, $value, $form_state);
$ret['valid'] = json_decode($value) !== NULL;
if (!$ret['valid']) {
$ret['message'] = t('The value needs to be a valid JSON object.') . ' ☆';
}
}
return $ret;
}