new: [elements:breadcrumb] Added possibility to have badges in action item

pull/93/head
Sami Mokaddem 2021-12-01 08:41:25 +01:00
parent ae2b666fbf
commit a6ecab5b47
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
1 changed files with 16 additions and 2 deletions

View File

@ -66,16 +66,22 @@ if (!empty($breadcrumb)) {
);
}
}
$badgeNumber = 0;
if (!empty($lastCrumb['actions'])) {
foreach ($lastCrumb['actions'] as $i => $actionEntry) {
if (!empty($actionEntry['url_vars'])) {
$actionEntry['url'] = $this->DataFromPath->buildStringFromDataPath($actionEntry['url'], $entity, $actionEntry['url_vars']);
}
if (!empty($actionEntry['badge'])) {
$badgeNumber += 1;
}
$breadcrumbAction .= sprintf(
'<a class="dropdown-item" href="#" onclick="%s"><i class="me-1 %s"></i>%s</a>',
'<a class="dropdown-item %s" href="#" onclick="%s"><i class="me-1 %s"></i>%s%s</a>',
!empty($actionEntry['variant']) ? sprintf('dropdown-item-%s', $actionEntry['variant']) : '',
sprintf('UI.overlayUntilResolve(this, UI.submissionModalAutoGuess(\'%s\'))', h(Router::url($actionEntry['url']))),
!empty($actionEntry['icon']) ? $this->FontAwesome->getClass(h($actionEntry['icon'])) : '',
h($actionEntry['label'])
h($actionEntry['label']),
!empty($actionEntry['badge']) ? $this->Bootstrap->badge($actionEntry['badge']) : ''
);
}
}
@ -97,6 +103,14 @@ echo $this->Breadcrumbs->render(
<?php if (!empty($breadcrumbAction)) : ?>
<a class="btn btn-primary btn-sm dropdown-toggle" href="#" role="button" id="dropdownMenuBreadcrumbAction" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<?= __('Actions') ?>
<?=
$badgeNumber == 0 ? '' : $this->Bootstrap->badge([
'text' => h($badgeNumber),
'variant' => 'warning',
'pill' => false,
'title' => __n('There is {0} action available', 'There are {0} actions available', $badgeNumber, h($badgeNumber)),
])
?>
</a>
<div class="dropdown-menu dropdown-menu-end" aria-labelledby="dropdownMenuBreadcrumbAction">
<?= $breadcrumbAction ?>