mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-06 12:45:30 +00:00
Fix complicated method.
This commit is contained in:
@@ -53,51 +53,76 @@ class Breadcrumbs extends AbstractExtension
|
|||||||
$name = Route::getCurrentRoute()->getName() ?? '';
|
$name = Route::getCurrentRoute()->getName() ?? '';
|
||||||
|
|
||||||
// loop for actual breadcrumb:
|
// loop for actual breadcrumb:
|
||||||
$arr = config(sprintf('bc.%s', $name));
|
$arr = config(sprintf('bc.%s', $name));
|
||||||
$breadcrumbs = [];
|
|
||||||
if (null === $arr) {
|
if (null === $arr) {
|
||||||
throw new FireflyException(sprintf('No breadcrumbs for route "%s".', $name));
|
throw new FireflyException(sprintf('No breadcrumbs for route "%s".', $name));
|
||||||
}
|
}
|
||||||
$hasParent = true;
|
$breadcrumbs = $this->getBreadcrumbs($arr);
|
||||||
$loop = 0;
|
|
||||||
while (true === $hasParent && $loop < 30) {
|
|
||||||
$breadcrumbs[] = $arr;
|
|
||||||
if (null === $arr['parent']) {
|
|
||||||
$hasParent = false;
|
|
||||||
|
|
||||||
}
|
return $this->getHtml($breadcrumbs);
|
||||||
if (null !== $arr['parent']) {
|
|
||||||
$arr = config(sprintf('bc.%s', $arr['parent']));
|
|
||||||
if (null === $arr) {
|
|
||||||
throw new FireflyException(sprintf('No (2) breadcrumbs for route "%s".', $name));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$loop++; // safety catch
|
|
||||||
}
|
|
||||||
// reverse order
|
|
||||||
$breadcrumbs = array_reverse($breadcrumbs);
|
|
||||||
|
|
||||||
// get HTML
|
|
||||||
$html = '<ol class="breadcrumb float-sm-right">';
|
|
||||||
foreach ($breadcrumbs as $index => $breadcrumb) {
|
|
||||||
$class = 'breadcrumb-item';
|
|
||||||
if ($index === count($breadcrumbs) - 1) {
|
|
||||||
// active!
|
|
||||||
$class = 'breadcrumb-item active';
|
|
||||||
}
|
|
||||||
$route = '#';
|
|
||||||
if (null !== $breadcrumb['static_route']) {
|
|
||||||
$route = route($breadcrumb['static_route']);
|
|
||||||
}
|
|
||||||
if (null !== $breadcrumb['dynamic_route']) {
|
|
||||||
$route = route($breadcrumb['dynamic_route'], $args[$index - 1] ?? []);
|
|
||||||
}
|
|
||||||
$html .= sprintf('<li class="%1$s"><a href="%2$s" title="%3$s">%3$s</a></li>', $class, $route, trans($breadcrumb['title']));
|
|
||||||
}
|
|
||||||
$html .= '</ol>';
|
|
||||||
return $html;
|
|
||||||
},
|
},
|
||||||
['is_safe' => ['html']]
|
['is_safe' => ['html']]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $arr
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
* @throws FireflyException
|
||||||
|
*/
|
||||||
|
private function getBreadcrumbs(array $arr)
|
||||||
|
{
|
||||||
|
$breadcrumbs = [];
|
||||||
|
$hasParent = true;
|
||||||
|
$loop = 0;
|
||||||
|
while (true === $hasParent && $loop < 30) {
|
||||||
|
$breadcrumbs[] = $arr;
|
||||||
|
if (null === $arr['parent']) {
|
||||||
|
$hasParent = false;
|
||||||
|
|
||||||
|
}
|
||||||
|
if (null !== $arr['parent']) {
|
||||||
|
$arr = config(sprintf('bc.%s', $arr['parent']));
|
||||||
|
if (null === $arr) {
|
||||||
|
throw new FireflyException(sprintf('No (2) breadcrumbs for route "%s".', $name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$loop++; // safety catch
|
||||||
|
}
|
||||||
|
|
||||||
|
// reverse order
|
||||||
|
return array_reverse($breadcrumbs);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $breadcrumbs
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function getHtml(array $breadcrumbs): string
|
||||||
|
{
|
||||||
|
// get HTML
|
||||||
|
$html = '<ol class="breadcrumb float-sm-right">';
|
||||||
|
foreach ($breadcrumbs as $index => $breadcrumb) {
|
||||||
|
$class = 'breadcrumb-item';
|
||||||
|
if ($index === count($breadcrumbs) - 1) {
|
||||||
|
// active!
|
||||||
|
$class = 'breadcrumb-item active';
|
||||||
|
}
|
||||||
|
$route = '#';
|
||||||
|
if (null !== $breadcrumb['static_route']) {
|
||||||
|
$route = route($breadcrumb['static_route']);
|
||||||
|
}
|
||||||
|
if (null !== $breadcrumb['dynamic_route']) {
|
||||||
|
$route = route($breadcrumb['dynamic_route'], $args[$index - 1] ?? []);
|
||||||
|
}
|
||||||
|
$html .= sprintf('<li class="%1$s"><a href="%2$s" title="%3$s">%3$s</a></li>', $class, $route, trans($breadcrumb['title']));
|
||||||
|
}
|
||||||
|
$html .= '</ol>';
|
||||||
|
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user