function _shs_json_callback_get_arguments in Simple hierarchical select 7
Helper function to get the (validated) arguments for a JSON callback.
Parameters
array $callback: Callback definition from shs_json_callbacks().
array $arguments: Unfiltered arguments posted with $.ajax().
Return value
array List of (validated) arguments for this callback. Any arguments not defined for this callback will be removed.
1 call to _shs_json_callback_get_arguments()
- shs_json in ./
shs.module - Menu callback to get data in JSON format.
File
- ./
shs.module, line 152 - Provides an additional widget for term fields to create hierarchical selects.
Code
function _shs_json_callback_get_arguments(array $callback, array $arguments) {
$result = array();
// Get arguments from callback definition.
$callback_arguments = $callback['arguments'];
foreach ($arguments as $key => $value) {
if (!isset($callback_arguments[$key])) {
continue;
}
$argument_valid = TRUE;
if (($validation_function = $callback_arguments[$key]) === FALSE) {
$argument_valid = FALSE;
continue;
}
$validation_arguments = array();
if (is_array($validation_function)) {
if (!isset($validation_function['callback'])) {
$argument_valid = FALSE;
watchdog('shs', 'Invalid structure for shs_json validation callback %key', array(
'%key' => $key,
), WATCHDOG_ERROR);
// Stop validation right now.
return $result;
}
foreach ($validation_function['arguments'] as $validation_argument_key => $validation_argument) {
if (strpos($validation_argument, '@') === 0) {
// Back-reference to callback argument.
$argument_name = substr($validation_argument, 1);
if (isset($arguments[$argument_name])) {
$validation_arguments[$validation_argument_key] = $arguments[$argument_name];
}
}
else {
$validation_arguments[$validation_argument_key] = $validation_argument;
}
}
$validation_function = $validation_function['callback'];
}
if (function_exists($validation_function)) {
// Validate argument.
if (empty($validation_arguments)) {
$argument_valid = call_user_func($validation_function, $value);
}
else {
$argument_valid = call_user_func($validation_function, $value, $validation_arguments);
}
}
if ($argument_valid) {
// Add argument and its value to the result list.
$result[$key] = $value;
}
}
return $result;
}