chg: [bookmarks] Make the rendering more lenient to malformed content

- fail gracefully rather than throwing 500s
pull/170/merge
iglocska 2024-09-17 00:08:49 +02:00
parent eb3f725e5b
commit 8e3e4316fb
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
1 changed files with 6 additions and 1 deletions

View File

@ -74,8 +74,13 @@ class NavigationComponent extends Component
$userSettingTable = TableRegistry::getTableLocator()->get('UserSettings'); $userSettingTable = TableRegistry::getTableLocator()->get('UserSettings');
$setting = $userSettingTable->getSettingByName($this->request->getAttribute('identity'), 'ui.bookmarks'); $setting = $userSettingTable->getSettingByName($this->request->getAttribute('identity'), 'ui.bookmarks');
$bookmarks = is_null($setting) ? [] : json_decode($setting->value, true); $bookmarks = is_null($setting) ? [] : json_decode($setting->value, true);
if (empty($bookmarks)) {
return [];
}
$links = array_map(function($bookmark) { $links = array_map(function($bookmark) {
if (!isset($bookmark['name']) || !isset($bookmark['label']) || !isset($bookmark['url'])) {
return [];
}
return [ return [
'name' => $bookmark['name'], 'name' => $bookmark['name'],
'label' => $bookmark['label'], 'label' => $bookmark['label'],