diff --git a/app/Support/Twig/Breadcrumbs.php b/app/Support/Twig/Breadcrumbs.php index b8c5f65abb..656d2bd0e1 100644 --- a/app/Support/Twig/Breadcrumbs.php +++ b/app/Support/Twig/Breadcrumbs.php @@ -53,51 +53,76 @@ class Breadcrumbs extends AbstractExtension $name = Route::getCurrentRoute()->getName() ?? ''; // loop for actual breadcrumb: - $arr = config(sprintf('bc.%s', $name)); - $breadcrumbs = []; + $arr = config(sprintf('bc.%s', $name)); + if (null === $arr) { throw new FireflyException(sprintf('No breadcrumbs for route "%s".', $name)); } - $hasParent = true; - $loop = 0; - while (true === $hasParent && $loop < 30) { - $breadcrumbs[] = $arr; - if (null === $arr['parent']) { - $hasParent = false; + $breadcrumbs = $this->getBreadcrumbs($arr); - } - 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); + return $this->getHtml($breadcrumbs); - // get HTML - $html = '
'; - return $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 = ' '; + + return $html; + } } \ No newline at end of file