function _slickgrid_drupal_to_js in Slickgrid 6
Amended version of drupal_to_js() Convert a php array into a js string, but allowing for function names (not wrapped in "")
1 call to _slickgrid_drupal_to_js()
- theme_slickgrid in ./
slickgrid.module - The main theme function for the slickgrid
File
- ./
slickgrid.module, line 644
Code
function _slickgrid_drupal_to_js($elements, $additional_function_names = array()) {
$function_names = array(
'formatter',
'validator',
'editor',
'setValueHandler',
'resizable',
);
if (count($additional_function_names)) {
$function_names += $additional_function_names;
}
if (count($elements)) {
$js_string = '[';
foreach ($elements as $element) {
$js_string .= $outer_conjunction . '{';
foreach ($element as $element_name => $element_value) {
$js_string .= $inner_conjunction;
if (in_array($element_name, $function_names) || is_numeric($element_value) || is_bool($element_value)) {
$js_string .= $element_name . ': ' . $element_value;
}
else {
$js_string .= $element_name . ': ' . drupal_to_js($element_value);
}
$inner_conjunction = ', ';
}
// End of foreach($element)
$js_string .= '}';
$inner_conjunction = ' ';
$outer_conjunction = ', ';
}
$js_string .= ']';
return $js_string;
}
}