options['group'] ?? '', label: 'dashboard.widget_bookmarks:widget.bookmarks.setting.groups.label', description: 'dashboard.widget_bookmarks:widget.bookmarks.setting.groups.description', readonly: array_key_exists('group', $this->options), enum: $this->getAvailableGroups(), ), new SettingDefinition( key: 'limit', type: 'int', default: (int)($this->options['limit'] ?? 0), label: 'dashboard.widget_bookmarks:widget.bookmarks.setting.limit.label', description: 'dashboard.widget_bookmarks:widget.bookmarks.setting.limit.description', readonly: array_key_exists('limit', $this->options), ), ]; } public function renderWidget(WidgetContext $context): WidgetResult { $view = $this->backendViewFactory->create($context->request); $view->assignMultiple([ 'options' => $this->options, 'settings' => $context->settings, 'configuration' => $this->configuration, ]); return new WidgetResult( content: $view->render('Widget/BookmarksWidget'), label: $this->resolveLabel($context->settings), refreshable: true, ); } public function getJavaScriptModuleInstructions(): array { return [ JavaScriptModuleInstruction::create('@typo3/dashboard/widget/bookmarks-widget-element.js'), ]; } private function getAvailableGroups(): array { $groups = [ '' => 'dashboard.widget_bookmarks:widget.bookmarks.setting.showAll', ]; // Only show groups that contain bookmarks $groupsWithBookmarks = []; foreach ($this->bookmarkService->getBookmarks() as $bookmark) { $groupsWithBookmarks[$bookmark->groupId] = true; } foreach ($this->bookmarkService->getGroups() as $group) { if (isset($groupsWithBookmarks[$group->id])) { $groups[(string)$group->id] = $group->label; } } return $groups; } private function resolveLabel(SettingsInterface $settings): ?string { $group = $settings->get('group'); if ($group !== '') { $groupId = is_numeric($group) ? (int)$group : $group; foreach ($this->bookmarkService->getGroups() as $bookmarkGroup) { if ($bookmarkGroup->id === $groupId) { $widgetTitle = $this->getLanguageService()->sL($this->configuration->getTitle()); return $widgetTitle . ': ' . $bookmarkGroup->label; } } } // Fall back to default widget title return null; } private function getLanguageService(): LanguageService { return $GLOBALS['LANG']; } }