Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.3] Tags: Fix broken aliases in routing #44515

Open
wants to merge 2 commits into
base: 5.3-dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions components/com_tags/src/Service/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Joomla\CMS\Menu\AbstractMenu;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\Database\DatabaseInterface;
use Joomla\Database\ParameterType;
use Joomla\Registry\Registry;
use Joomla\Utilities\ArrayHelper;

Expand Down Expand Up @@ -98,6 +99,31 @@ public function __construct(SiteApplication $app, AbstractMenu $menu, ?CategoryF
*/
public function preprocess($query)
{
// Make sure the alias for the tags is correct
if (isset($query['id'])) {
if (!is_array($query['id'])) {
$query['id'] = [$query['id']];
}

foreach ($query['id'] as &$item) {
if (!strpos($item, ':')) {
$dbquery = $this->db->getQuery(true);
$id = (int) $item;

$dbquery->select($dbquery->quoteName('alias'))
->from('#__tags')
->where($dbquery->quoteName('id') . ' = :key')
->bind(':key', $id, ParameterType::INTEGER);

$obj = $this->db->setQuery($dbquery)->loadObject();

if ($obj) {
$item .= ':' . $obj->alias;
}
}
}
}

$active = $this->menu->getActive();

/**
Expand Down Expand Up @@ -196,10 +222,6 @@ public function build(&$query)
if (isset($query['id'])) {
$ids = $query['id'];

if (!\is_array($ids)) {
$ids = [$ids];
}

foreach ($ids as $id) {
$segments[] = $id;
}
Expand Down