public function EmitController::emit in Radioactivity 8.3
Same name and namespace in other branches
- 8.2 src/Controller/EmitController.php \Drupal\radioactivity\Controller\EmitController::emit()
- 4.0.x src/Controller/EmitController.php \Drupal\radioactivity\Controller\EmitController::emit()
Callback for /radioactivity/emit.
Parameters
\Symfony\Component\HttpFoundation\Request $request: The request object.
Return value
\Symfony\Component\HttpFoundation\JsonResponse Response object.
1 string reference to 'EmitController::emit'
File
- src/
Controller/ EmitController.php, line 56
Class
- EmitController
- Controller for radioactivity emit routes.
Namespace
Drupal\radioactivity\ControllerCode
public function emit(Request $request) {
$postData = $request
->getContent();
if (empty($postData)) {
return new JsonResponse([
'status' => 'error',
'message' => 'Empty request.',
]);
}
$count = 0;
$incidents = Json::decode($postData);
foreach ($incidents as $data) {
$incident = Incident::createFromPostData($data);
if (!$incident
->isValid()) {
return $this
->buildJsonStatusResponse('error', "invalid incident ({$count}).");
}
$this->incidentStorage
->addIncident($incident);
$count++;
}
return $this
->buildJsonStatusResponse('ok', "{$count} incidents added.");
}