Skip to content

Commit

Permalink
Refactor bootstrapBreadcrumb() method
Browse files Browse the repository at this point in the history
  • Loading branch information
webeweb committed Jul 16, 2018
1 parent b4333cd commit 653760f
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions Twig/Extension/Component/AbstractComponentTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,24 +107,16 @@ protected function bootstrapBadge($content) {
private function bootstrapBreadcrumb(NavigationNode $node, $last) {

// Initialize the template.
$template = "<li%class%>%innerHTML%</li>";
$template = "<li%attributes%>%innerHTML%</li>";

// Initialize the parameters.
$class = true === $node->getActive() && true == $last ? " class=\"active\"" : "";
$innerHTML = [];
$content = $this->getTranslator()->trans($node->getId());

if (false === $last) {
$innerHTML[] = "<a href=\"";
$innerHTML[] = $node->getRoute();
$innerHTML[] = "\">";
}
$innerHTML[] = $this->getTranslator()->trans($node->getId());
if (false === $last) {
$innerHTML[] = "</a>";
}
$attributes = true === $node->getActive() && true == $last ? " class=\"active\"" : "";
$innerHTML = true === $last ? $content : $this->bootstrapDOMObject("a", "href=\"" . $node->getRoute() . "\"", $content);

// Return the HTML.
return StringUtility::replace($template, ["%class%", "%innerHTML%"], [$class, implode("", $innerHTML)]);
return StringUtility::replace($template, ["%attributes%", "%innerHTML%"], [$attributes, $innerHTML]);
}

/**
Expand Down

0 comments on commit 653760f

Please sign in to comment.