Skip to content

Commit

Permalink
Revert "Allow tag router to generate internal routes exclusivelly by …
Browse files Browse the repository at this point in the history
…passing "internal" param"

This reverts commit 27aa463.

Silly me, we can just use `_eztagsTag` route.
  • Loading branch information
emodric committed Sep 10, 2015
1 parent 82a71a8 commit 52b8abf
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 51 deletions.
3 changes: 1 addition & 2 deletions Resources/doc/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
Netgen Tags Bundle changelog
============================

2.0.4 (11.09.2015)
2.0.4 (10.09.2015)
------------------

* Allow generating internal tag routes by setting `internal` parameter `true` when generating route
* Replace `ez_trans_prop` usage with `netgen_tags_tag_keyword` function, to be able to get keyword by tag ID also

2.0.3 (10.09.2015)
Expand Down
96 changes: 47 additions & 49 deletions Routing/Generator/TagUrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,65 +63,58 @@ public function __construct(
*/
public function doGenerate($tag, array $parameters)
{
$originalTagId = $tag->id;
$generateInternal = isset($parameters['internal']) && $parameters['internal'] === true;

if (!$generateInternal) {
if (isset($parameters['siteaccess'])) {
// We generate for a different siteaccess, so potentially in a different language.
$languages = $this->configResolver->getParameter('languages', null, $parameters['siteaccess']);
} else {
$languages = $this->configResolver->getParameter('languages');
}
if (isset($parameters['siteaccess'])) {
// We generate for a different siteaccess, so potentially in a different language.
$languages = $this->configResolver->getParameter('languages', null, $parameters['siteaccess']);
unset($parameters['siteaccess']);
} else {
$languages = $this->configResolver->getParameter('languages');
}

$tagUrl = '';
$tagId = $tag->id;
$tagUrl = '';
$isInternal = false;
$originalTagId = $tagId = $tag->id;

try {
do {
$tag = $this->tagsService->loadTag($tagId, $languages);
try {
do {
$tag = $this->tagsService->loadTag($tagId, $languages);

$tagKeyword = null;
foreach ($languages as $language) {
$tagKeyword = $tag->getKeyword($language);
if (!empty($tagKeyword)) {
break;
}
$tagKeyword = null;
foreach ($languages as $language) {
$tagKeyword = $tag->getKeyword($language);
if (!empty($tagKeyword)) {
break;
}
}

if (empty($tagKeyword)) {
if ($tag->alwaysAvailable) {
$tagKeyword = $tag->getKeyword();
}

if (empty($tagKeyword)) {
throw new LogicException("Unknown error when generating URL for tag ID #{$originalTagId}");
}
if (empty($tagKeyword)) {
if ($tag->alwaysAvailable) {
$tagKeyword = $tag->getKeyword();
}

$tagUrl = '/' . $tagKeyword . $tagUrl;

$tagId = $tag->parentTagId;
} while ($tagId > 0);
} catch (NotFoundException $e) {
$generateInternal = true;
} catch (LogicException $e) {
if ($this->logger !== null) {
$this->logger->warning($e->getMessage());
if (empty($tagKeyword)) {
throw new LogicException("Unknown error when generating URL for tag ID #{$originalTagId}");
}
}

$generateInternal = true;
}
}

unset($parameters['internal'], $parameters['siteaccess']);
$tagUrl = '/' . $tagKeyword . $tagUrl;

$queryString = '';
if (!empty($parameters)) {
$queryString = '?' . http_build_query($parameters, '', '&');
}
$tagId = $tag->parentTagId;
} while ($tagId > 0);
} catch (NotFoundException $e) {
$isInternal = true;
$tagUrl = $this->defaultRouter->generate(
self::INTERNAL_TAG_ROUTE,
array(
'tagId' => $originalTagId,
)
);
} catch (LogicException $e) {
if ($this->logger !== null) {
$this->logger->warning($e->getMessage());
}

if ($generateInternal) {
$isInternal = true;
$tagUrl = $this->defaultRouter->generate(
self::INTERNAL_TAG_ROUTE,
array(
Expand All @@ -130,7 +123,12 @@ public function doGenerate($tag, array $parameters)
);
}

return (!$generateInternal ? $this->getPathPrefix() : '') . '/' . trim($tagUrl, '/') . $queryString;
$queryString = '';
if (!empty($parameters)) {
$queryString = '?' . http_build_query($parameters, '', '&');
}

return (!$isInternal ? $this->getPathPrefix() : '') . '/' . trim($tagUrl, '/') . $queryString;
}

/**
Expand Down

0 comments on commit 52b8abf

Please sign in to comment.