protected function MediaController::getErrorResponse in Gutenberg 8.2
Returns the error response including status messages.
Parameters
string $error: The original error.
Return value
array JSON response to return to the client.
1 call to MediaController::getErrorResponse()
- MediaController::upload in src/
Controller/ MediaController.php - Upload files, save as file and media entity if possible.
File
- src/
Controller/ MediaController.php, line 299
Class
- MediaController
- Returns responses for our image routes.
Namespace
Drupal\gutenberg\ControllerCode
protected function getErrorResponse($error) {
$messages = $this
->messenger()
->deleteAll();
if ($messages) {
// Display the status messages along with the original error.
// @todo (HACKY) Leverage AjaxRenderer + "_wrapper_format=drupal_ajax" to handle this instead.
$message_entries = [];
foreach ([
'error',
'warning',
'status',
] as $status) {
if (isset($messages[$status])) {
/* @noinspection SlowArrayOperationsInLoopInspection */
$message_entries = array_merge($message_entries, $messages[$status]);
}
}
if ($message_entries) {
$render = [
'#type' => 'inline_template',
'#template' => '<div class="gutenberg-error--initial">{{ error }}</div><div class="gutenberg-error--other-messages">{{ messages }}</div>',
'#context' => [
'error' => $error,
'messages' => [
'#theme' => 'item_list',
'#list_type' => 'ul',
'#items' => $message_entries,
],
],
];
$output = $this->renderer
->renderRoot($render);
return [
'error' => $output,
// Render as Raw HTML.
'rawHTML' => TRUE,
];
}
}
return [
'error' => $error,
];
}