Add support for non-numeric menu counter values (#4661)
Documented in https://github.com/octobercms/docs/pull/447
This commit is contained in:
parent
3a7224c2ec
commit
0522f50bf4
|
|
@ -44,6 +44,11 @@ class MainMenuItem
|
|||
*/
|
||||
public $counterLabel;
|
||||
|
||||
/**
|
||||
* @var null|string
|
||||
*/
|
||||
public $badge;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
|
@ -118,6 +123,7 @@ class MainMenuItem
|
|||
$instance->iconSvg = $data['iconSvg'] ?? null;
|
||||
$instance->counter = $data['counter'] ?? null;
|
||||
$instance->counterLabel = $data['counterLabel'] ?? null;
|
||||
$instance->badge = $data['badge'] ?? null;
|
||||
$instance->permissions = $data['permissions'] ?? $instance->permissions;
|
||||
$instance->order = $data['order'] ?? $instance->order;
|
||||
return $instance;
|
||||
|
|
|
|||
|
|
@ -175,6 +175,8 @@ class NavigationManager
|
|||
* - counter - an optional numeric value to output near the menu icon. The value should be
|
||||
* a number or a callable returning a number.
|
||||
* - counterLabel - an optional string value to describe the numeric reference in counter.
|
||||
* - badge - an optional string value to output near the menu icon. The value should be
|
||||
* a string. This value will override the counter if set.
|
||||
* @param string $owner Specifies the menu items owner plugin or module in the format Author.Plugin.
|
||||
* @param array $definitions An array of the menu item definitions.
|
||||
* @throws SystemException
|
||||
|
|
@ -349,6 +351,10 @@ class NavigationManager
|
|||
}
|
||||
|
||||
foreach ($this->items as $item) {
|
||||
if ($item->badge) {
|
||||
$item->counter = (string) $item->badge;
|
||||
continue;
|
||||
}
|
||||
if ($item->counter === false) {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -360,6 +366,9 @@ class NavigationManager
|
|||
} elseif (!empty($sideItems = $this->listSideMenuItems($item->owner, $item->code))) {
|
||||
$item->counter = 0;
|
||||
foreach ($sideItems as $sideItem) {
|
||||
if ($sideItem->badge) {
|
||||
continue;
|
||||
}
|
||||
$item->counter += $sideItem->counter;
|
||||
}
|
||||
}
|
||||
|
|
@ -402,6 +411,10 @@ class NavigationManager
|
|||
$items = $activeItem->sideMenu;
|
||||
|
||||
foreach ($items as $item) {
|
||||
if ($item->badge) {
|
||||
$item->counter = (string) $item->badge;
|
||||
continue;
|
||||
}
|
||||
if ($item->counter !== null && is_callable($item->counter)) {
|
||||
$item->counter = call_user_func($item->counter, $item);
|
||||
if (empty($item->counter)) {
|
||||
|
|
|
|||
|
|
@ -47,6 +47,11 @@ class SideMenuItem
|
|||
*/
|
||||
public $counterLabel;
|
||||
|
||||
/**
|
||||
* @var null|string
|
||||
*/
|
||||
public $badge;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
@ -110,6 +115,7 @@ class SideMenuItem
|
|||
$instance->counter = $data['counter'] ?? null;
|
||||
$instance->counterLabel = $data['counterLabel'] ?? null;
|
||||
$instance->attributes = $data['attributes'] ?? $instance->attributes;
|
||||
$instance->badge = $data['badge'] ?? null;
|
||||
$instance->permissions = $data['permissions'] ?? $instance->permissions;
|
||||
$instance->order = $data['order'] ?? $instance->order;
|
||||
return $instance;
|
||||
|
|
|
|||
Loading…
Reference in New Issue