Skip to content

Commit

Permalink
chore: Tolerate errors when rendering widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
hellopablo committed Aug 7, 2024
1 parent c7f68ac commit fe16471
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions src/Admin/Controller/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,25 +109,32 @@ protected function getDashboardWidgets(): array
array_filter(
array_map(function (\Nails\Admin\Resource\Dashboard\Widget $oWidget) {

$sClass = $oWidget->slug;
/** @var \Nails\Admin\Interfaces\Dashboard\Widget $oInstance */
$oInstance = new $sClass($oWidget->config);

return $oInstance->isEnabled() ? [
'id' => $oWidget->id,
'slug' => $oWidget->slug,
'title' => $oInstance->getTitle(),
'description' => $oInstance->getDescription(),
'image' => $oInstance->getImage(),
'body' => $oInstance->getBody(),
'padded' => $oInstance->isPadded(),
'configurable' => $oInstance->isConfigurable(),
'x' => $oWidget->x,
'y' => $oWidget->y,
'w' => $oWidget->w,
'h' => $oWidget->h,
'config' => (object) $oWidget->config,
] : null;
try {

$sClass = $oWidget->slug;
/** @var \Nails\Admin\Interfaces\Dashboard\Widget $oInstance */
$oInstance = new $sClass($oWidget->config);

return $oInstance->isEnabled() ? [
'id' => $oWidget->id,
'slug' => $oWidget->slug,
'title' => $oInstance->getTitle(),
'description' => $oInstance->getDescription(),
'image' => $oInstance->getImage(),
'body' => $oInstance->getBody(),
'padded' => $oInstance->isPadded(),
'configurable' => $oInstance->isConfigurable(),
'x' => $oWidget->x,
'y' => $oWidget->y,
'w' => $oWidget->w,
'h' => $oWidget->h,
'config' => (object) $oWidget->config,
] : null;

} catch (\Throwable $e) {
return null;
}

}, $oWidgets->getWidgetsForUser())
)
);
Expand Down

0 comments on commit fe16471

Please sign in to comment.