class DefaultController in Matrix field 8.2
Same name in this branch
- 8.2 src/DefaultController.php \Drupal\matrix\DefaultController
- 8.2 src/Controller/DefaultController.php \Drupal\matrix\Controller\DefaultController
Default controller for the matrix module.
Hierarchy
- class \Drupal\matrix\DefaultController extends \Drupal\matrix\ControllerBase
Expanded class hierarchy of DefaultController
File
- src/
DefaultController.php, line 8
Namespace
Drupal\matrixView source
class DefaultController extends ControllerBase {
public function matrix_custom_calculation_callback() {
$callback = $_POST['callback'];
$data = explode(",", $_POST['data']);
$functions = \Drupal::moduleHandler()
->invokeAll('matrix_functions');
//ensure the callback is allowed
if (!in_array($callback, array_keys($functions['calculation']))) {
drupal_json_output([
'error' => t('Calcuation callback function not available'),
]);
exit;
}
//ensure the data is safe
foreach ($data as $id => $d) {
$data[$id] = check_plain($d);
}
$result = call_user_func($callback, $data);
drupal_json_output([
'data' => check_plain($result),
]);
exit;
}
}