In Compass Core menu items can be used to create a menu structure for your application.
To add menu items...
Menu Items Badges can be used to dynamically easily add a badge to a menu item. The badge will be updated automatically when the resource collection is updated.
To add a badge to a menu item, you will first need to add a service class that implements the Noardcode\Compass\Menu\Contracts\MenuItemWithBadgeInterface interface.
class TaskItemService implements MenuItemWithBadgeInterface
The interface has two methods that need to be implemented. The getBadgeCounter method is used to get the count of any number relating to the menu item in question.
The getBadgeColor method is used to set the color of the badge. The color can be any of the predefined bootstrap colors or a hex color code.
public function __construct(MenuItem $menuItem)
{
//
}
public function getBadgeContent(): ?string
{
return 0;
}
public function getBadgeColor(): ?string
{
return '#000000'; // Or: red, blue, green, yellow, orange, purple, pink, teal, cyan, white, gray, gray-dark, primary, secondary, success, info, warning, danger, light, dark
}
If the counter is 0, the badge will not be shown. If a color is not set, the default color will be used.
The service can be added to the menu item by adding the fully qualified class name to the column service_class in the MenuItem database table.
For a Menu Item Badge to work, the following rules apply:
Noardcode\Compass\Menu\Contracts\MenuItemWithBadgeInterface interface.service_class column in the MenuItem database table.