Navigation and badges

The header is configured in YAML: entries by permission or controller, submenus, counters, icon-only entries with a second counter.

The code

app/_config/navigation.yml – main_navigation whole file
Atwx\SilverstripeFrontdeskKit\Controller\FrontdeskController:
main_navigation:
dashboard:
title: 'Dashboard'
segment: 'dashboard'
permission: 'FDK_PROJECTS_VIEW'
clients:
title: 'Clients'
segment: 'clients'
controller: 'App\Controllers\ClientController'
contacts:
title: 'Contacts'
segment: 'contacts'
controller: 'App\Controllers\ContactController'
projects:
title: 'Projects'
segment: 'projects'
controller: 'App\Controllers\ProjectController'
tasks:
title: 'Tasks'
segment: 'tasks'
link: 'tasks?view=mine'
controller: 'App\Controllers\TaskController'
icon: 'square-check'
icon_only: true
badge: 'App\Controllers\TaskController::countMine'
badge_secondary: 'App\Controllers\TaskController::countUnassigned'
more:
title: 'More'
children:
catalogs:
title: 'Catalogs'
segment: 'catalogs'
controller: 'Atwx\SilverstripeFrontdeskKit\Controller\CatalogController'
features:
title: 'All features'
segment: 'features'
secondary_navigation:
github:
title: 'Kit on GitHub'
link: 'https://github.com/atwx/silverstripe-frontdesk-kit'
app/src/Controllers/TaskController.php – The counters whole file
/**
* Badge of the navigation: my open tasks.
*/
public static function countMine(): int
{
$me = (int) Security::getCurrentUser()?->ID;
return $me ? Task::get()->filter(['AssigneeID' => $me])->exclude('Status', 'done')->count() : 0;
}

/**
* Second badge: open tasks without an assignee.
*/
public static function countUnassigned(): int
{
return Security::getCurrentUser()
? Task::get()->filter(['AssigneeID' => 0])->exclude('Status', 'done')->count()
: 0;
}