Skip to content

Commit

Permalink
Merge pull request #1421 from bolt/bugfix/record-link
Browse files Browse the repository at this point in the history
Pretty record|link when localization is enabled
  • Loading branch information
bobdenotter authored May 29, 2020
2 parents 6ff15a7 + 4583fb2 commit 2fc95c2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Canonical.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public function setPath(?string $route = null, array $params = []): void
}
}

private function getCanonicalRoute(string $route, array &$params = []): string
public function getCanonicalRoute(string $route, array &$params = []): string
{
$routes = new Collection($this->router->getRouteCollection()->getIterator());
$currentController = $routes->get($route)->getDefault('_controller');
Expand Down
12 changes: 10 additions & 2 deletions src/Twig/ContentExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Bolt\Twig;

use Bolt\Canonical;
use Bolt\Configuration\Config;
use Bolt\Configuration\Content\ContentType;
use Bolt\Entity\Content;
Expand Down Expand Up @@ -68,6 +69,9 @@ class ContentExtension extends AbstractExtension
/** @var TranslatorInterface */
private $translator;

/** @var Canonical */
private $canonical;

public function __construct(
UrlGeneratorInterface $urlGenerator,
ContentRepository $contentRepository,
Expand All @@ -77,7 +81,8 @@ public function __construct(
Config $config,
Query $query,
TaxonomyRepository $taxonomyRepository,
TranslatorInterface $translator
TranslatorInterface $translator,
Canonical $canonical
) {
$this->urlGenerator = $urlGenerator;
$this->contentRepository = $contentRepository;
Expand All @@ -88,6 +93,7 @@ public function __construct(
$this->query = $query;
$this->taxonomyRepository = $taxonomyRepository;
$this->translator = $translator;
$this->canonical = $canonical;
}

/**
Expand Down Expand Up @@ -390,9 +396,11 @@ public function getStatusLink(Content $content, bool $absolute = false): ?string

private function generateLink(string $route, array $params, $canonical = false): string
{
$canonicalRoute = $this->canonical->getCanonicalRoute($route, $params);

try {
$link = $this->urlGenerator->generate(
$route,
$canonicalRoute,
$params,
$canonical ? UrlGeneratorInterface::ABSOLUTE_URL : UrlGeneratorInterface::ABSOLUTE_PATH
);
Expand Down

0 comments on commit 2fc95c2

Please sign in to comment.