Skip to content

Commit

Permalink
[4.0] Multilingual : Correcting info-block category and parent catego…
Browse files Browse the repository at this point in the history
…ry urls (joomla#21916)

* [4.0] Correcting info-block category and parent category urls

* Getting rid of category slugs thanks Hannes

* missing one cat language variable

* Correcting routing for archived

* Getting the active language when item is tagged to ALL

* Load current language when item is set to ALL

* factory not used

* better code for menurules thanks @csthomas
  • Loading branch information
infograf768 authored and laoneo committed Sep 6, 2018
1 parent 7fa1893 commit 169a8e1
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 50 deletions.
6 changes: 4 additions & 2 deletions components/com_content/Model/ArticleModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ public function getItem($pk = null)
->where($db->quoteName('wa.stage_id') . ' = ' . $db->quoteName('ws.id'));

// Join on category table.
$query->select('c.title AS category_title, c.alias AS category_alias, c.access AS category_access')
$query->select('c.title AS category_title, c.alias AS category_alias, c.access AS category_access,' .
'c.language AS category_language')
->innerJoin('#__categories AS c on c.id = a.catid')
->where('c.published > 0');

Expand All @@ -130,7 +131,8 @@ public function getItem($pk = null)
}

// Join over the categories to get parent category titles
$query->select('parent.title as parent_title, parent.id as parent_id, parent.path as parent_route, parent.alias as parent_alias')
$query->select('parent.title as parent_title, parent.id as parent_id, parent.path as parent_route,' .
'parent.alias as parent_alias, parent.language as parent_language')
->join('LEFT', '#__categories as parent ON parent.id = c.parent_id');

// Join on voting table
Expand Down
6 changes: 4 additions & 2 deletions components/com_content/Model/ArticlesModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ protected function getListQuery()
->join('LEFT', '#__workflow_stages AS ws ON ws.id = wa.stage_id');

// Join over the categories.
$query->select('c.title AS category_title, c.path AS category_route, c.access AS category_access, c.alias AS category_alias')
$query->select('c.title AS category_title, c.path AS category_route, c.access AS category_access, c.alias AS category_alias,' .
'c.language AS category_language')
->select('c.published, c.published AS parents_published, c.lft')
->join('LEFT', '#__categories AS c ON c.id = a.catid');

Expand All @@ -262,7 +263,8 @@ protected function getListQuery()
->join('LEFT', '#__users AS uam ON uam.id = a.modified_by');

// Join over the categories to get parent category titles
$query->select('parent.title as parent_title, parent.id as parent_id, parent.path as parent_route, parent.alias as parent_alias')
$query->select('parent.title as parent_title, parent.id as parent_id, parent.path as parent_route, parent.alias as parent_alias,' .
'parent.language as parent_language')
->join('LEFT', '#__categories as parent ON parent.id = c.parent_id');

if (PluginHelper::isEnabled('content', 'vote'))
Expand Down
5 changes: 2 additions & 3 deletions components/com_content/View/Archive/HtmlView.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,12 @@ public function display($tpl = null)

foreach ($items as $item)
{
$item->catslug = $item->category_alias ? ($item->catid . ':' . $item->category_alias) : $item->catid;
$item->parent_slug = $item->parent_alias ? ($item->parent_id . ':' . $item->parent_alias) : $item->parent_id;
$item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id;

// No link for ROOT category
if ($item->parent_alias === 'root')
{
$item->parent_slug = null;
$item->parent_id = null;
}

$item->event = new \stdClass;
Expand Down
8 changes: 3 additions & 5 deletions components/com_content/View/Article/HtmlView.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,12 @@ public function display($tpl = null)
$item->tagLayout = new FileLayout('joomla.content.tags');

// Add router helpers.
$item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id;
$item->catslug = $item->category_alias ? ($item->catid . ':' . $item->category_alias) : $item->catid;
$item->parent_slug = $item->parent_alias ? ($item->parent_id . ':' . $item->parent_alias) : $item->parent_id;
$item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id;

// No link for ROOT category
if ($item->parent_alias === 'root')
{
$item->parent_slug = null;
$item->parent_id = null;
}

// TODO: Change based on shownoauth
Expand Down Expand Up @@ -302,7 +300,7 @@ protected function _prepareDocument()

while ($category && ($menu->query['option'] !== 'com_content' || $menu->query['view'] === 'article' || $id != $category->id) && $category->id > 1)
{
$path[] = array('title' => $category->title, 'link' => \ContentHelperRoute::getCategoryRoute($category->id));
$path[] = array('title' => $category->title, 'link' => \ContentHelperRoute::getCategoryRoute($category->id, $category->language));
$category = $category->getParent();
}

Expand Down
7 changes: 2 additions & 5 deletions components/com_content/View/Category/HtmlView.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,12 @@ public function display($tpl = null)
{
$item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id;

$item->parent_slug = $item->parent_alias ? ($item->parent_id . ':' . $item->parent_alias) : $item->parent_id;

// No link for ROOT category
if ($item->parent_alias === 'root')
{
$item->parent_slug = null;
$item->parent_id = null;
}

$item->catslug = $item->category_alias ? ($item->catid . ':' . $item->category_alias) : $item->catid;
$item->event = new \stdClass;

// Old plugins: Ensure that text property is available
Expand Down Expand Up @@ -290,7 +287,7 @@ protected function prepareDocument()

while (($menu->query['option'] !== 'com_content' || $menu->query['view'] === 'article' || $id != $category->id) && $category->id > 1)
{
$path[] = array('title' => $category->title, 'link' => \ContentHelperRoute::getCategoryRoute($category->id));
$path[] = array('title' => $category->title, 'link' => \ContentHelperRoute::getCategoryRoute($category->id, $category->language));
$category = $category->getParent();
}

Expand Down
6 changes: 2 additions & 4 deletions components/com_content/View/Featured/HtmlView.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,12 @@ public function display($tpl = null)
// Compute the article slugs and prepare introtext (runs content plugins).
foreach ($items as &$item)
{
$item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id;
$item->catslug = $item->category_alias ? ($item->catid . ':' . $item->category_alias) : $item->catid;
$item->parent_slug = $item->parent_alias ? ($item->parent_id . ':' . $item->parent_alias) : $item->parent_id;
$item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id;

// No link for ROOT category
if ($item->parent_alias === 'root')
{
$item->parent_slug = null;
$item->parent_id = null;
}

$item->event = new \stdClass;
Expand Down
8 changes: 0 additions & 8 deletions components/com_content/helpers/route.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,6 @@ public static function getCategoryRoute($catid, $language = 0)
{
$link .= '&lang=' . $language;
}

$jinput = JFactory::getApplication()->input;
$layout = $jinput->get('layout');

if ($layout !== '')
{
$link .= '&layout=' . $layout;
}
}

return $link;
Expand Down
34 changes: 23 additions & 11 deletions components/com_content/tmpl/archive/default_items.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,15 @@
<?php echo JText::_('COM_CONTENT_ARTICLE_INFO'); ?>
</dt>

<?php if ($params->get('show_parent_category') && !empty($item->parent_slug)) : ?>
<?php if ($params->get('show_parent_category') && !empty($item->parent_id)) : ?>
<dd>
<div class="parent-category-name">
<?php $title = $this->escape($item->parent_title); ?>
<?php if ($params->get('link_parent_category') && !empty($item->parent_slug)) : ?>
<?php $url = '<a href="' . Route::_(ContentHelperRoute::getCategoryRoute($item->parent_slug)) . '" itemprop="genre">' . $title . '</a>'; ?>
<?php if ($params->get('link_parent_category') && !empty($item->parent_id)) : ?>
<?php $url = '<a href="' . Route::_(
ContentHelperRoute::getCategoryRoute($item->parent_id, $item->parent_language)
)
. '" itemprop="genre">' . $title . '</a>'; ?>
<?php echo JText::sprintf('COM_CONTENT_PARENT', $url); ?>
<?php else : ?>
<?php echo JText::sprintf('COM_CONTENT_PARENT', '<span itemprop="genre">' . $title . '</span>'); ?>
Expand All @@ -72,8 +75,11 @@
<dd>
<div class="category-name">
<?php $title = $this->escape($item->category_title); ?>
<?php if ($params->get('link_category') && $item->catslug) : ?>
<?php $url = '<a href="' . Route::_(ContentHelperRoute::getCategoryRoute($item->catslug)) . '" itemprop="genre">' . $title . '</a>'; ?>
<?php if ($params->get('link_category') && $item->catid) : ?>
<?php $url = '<a href="' . Route::_(
ContentHelperRoute::getCategoryRoute($item->catid, $item->category_language)
)
. '" itemprop="genre">' . $title . '</a>'; ?>
<?php echo JText::sprintf('COM_CONTENT_CATEGORY', $url); ?>
<?php else : ?>
<?php echo JText::sprintf('COM_CONTENT_CATEGORY', '<span itemprop="genre">' . $title . '</span>'); ?>
Expand Down Expand Up @@ -141,12 +147,15 @@
<dt class="article-info-term"><?php echo JText::_('COM_CONTENT_ARTICLE_INFO'); ?></dt>

<?php if ($info == 1) : ?>
<?php if ($params->get('show_parent_category') && !empty($item->parent_slug)) : ?>
<?php if ($params->get('show_parent_category') && !empty($item->parent_id)) : ?>
<dd>
<div class="parent-category-name">
<?php $title = $this->escape($item->parent_title); ?>
<?php if ($params->get('link_parent_category') && $item->parent_slug) : ?>
<?php $url = '<a href="' . Route::_(ContentHelperRoute::getCategoryRoute($item->parent_slug)) . '" itemprop="genre">' . $title . '</a>'; ?>
<?php if ($params->get('link_parent_category') && $item->parent_id) : ?>
<?php $url = '<a href="' . Route::_(
ContentHelperRoute::getCategoryRoute($item->parent_id, $item->parent_language)
)
. '" itemprop="genre">' . $title . '</a>'; ?>
<?php echo JText::sprintf('COM_CONTENT_PARENT', $url); ?>
<?php else : ?>
<?php echo JText::sprintf('COM_CONTENT_PARENT', '<span itemprop="genre">' . $title . '</span>'); ?>
Expand All @@ -158,8 +167,11 @@
<dd>
<div class="category-name">
<?php $title = $this->escape($item->category_title); ?>
<?php if ($params->get('link_category') && $item->catslug) : ?>
<?php $url = '<a href="' . Route::_(ContentHelperRoute::getCategoryRoute($item->catslug)) . '" itemprop="genre">' . $title . '</a>'; ?>
<?php if ($params->get('link_category') && $item->catid) : ?>
<?php $url = '<a href="' . Route::_(
ContentHelperRoute::getCategoryRoute($item->catid, $item->category_language)
)
. '" itemprop="genre">' . $title . '</a>'; ?>
<?php echo JText::sprintf('COM_CONTENT_CATEGORY', $url); ?>
<?php else : ?>
<?php echo JText::sprintf('COM_CONTENT_CATEGORY', '<span itemprop="genre">' . $title . '</span>'); ?>
Expand Down Expand Up @@ -223,6 +235,6 @@
</p>
<?php endif; ?>
<div class="com-content-archive__pagination">
<?php echo $this->pagination->getPagesLinks(); ?>
<?php echo $this->pagination->getPagesLinks(); ?>
</div>
</div>
4 changes: 2 additions & 2 deletions components/com_content/tmpl/category/blog_children.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@
<?php echo $child->getNumItems(true); ?>
</span>
<?php endif; ?>
<a href="<?php echo Route::_(ContentHelperRoute::getCategoryRoute($child->id)); ?>">
<a href="<?php echo Route::_(ContentHelperRoute::getCategoryRoute($child->id, $child->language)); ?>">
<?php echo $this->escape($child->title); ?></a>

<?php if ($this->maxLevel > 1 && count($child->getChildren()) > 0) : ?>
<a href="#category-<?php echo $child->id; ?>" data-toggle="collapse" data-toggle="button" class="btn btn-xs float-right" aria-label="<?php echo Text::_('JGLOBAL_EXPAND_CATEGORIES'); ?>"><span class="icon-plus" aria-hidden="true"></span></a>
<?php endif; ?>
</h3>
<?php else : ?>
<h3 class="page-header item-title"><a href="<?php echo Route::_(ContentHelperRoute::getCategoryRoute($child->id)); ?>">
<h3 class="page-header item-title"><a href="<?php echo Route::_(ContentHelperRoute::getCategoryRoute($child->id, $child->language)); ?>">
<?php echo $this->escape($child->title); ?></a>
<?php if ( $this->params->get('show_cat_num_articles', 1)) : ?>
<span class="badge badge-info tip hasTooltip" title="<?php echo HTMLHelper::_('tooltipText', 'COM_CONTENT_NUM_ITEMS_TIP'); ?>">
Expand Down
4 changes: 2 additions & 2 deletions components/com_content/tmpl/category/default_children.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@
<?php echo $child->getNumItems(true); ?>
</span>
<?php endif; ?>
<a href="<?php echo Route::_(ContentHelperRoute::getCategoryRoute($child->id)); ?>">
<a href="<?php echo Route::_(ContentHelperRoute::getCategoryRoute($child->id, $child->language)); ?>">
<?php echo $this->escape($child->title); ?></a>

<?php if (count($child->getChildren()) > 0 && $this->maxLevel > 1) : ?>
<a href="#category-<?php echo $child->id; ?>" data-toggle="collapse" data-toggle="button" class="btn btn-xs float-right" aria-label="<?php echo Text::_('JGLOBAL_EXPAND_CATEGORIES'); ?>"><span class="icon-plus" aria-hidden="true"></span></a>
<?php endif; ?>
</h3>
<?php else : ?>
<h3 class="page-header item-title"><a href="<?php echo Route::_(ContentHelperRoute::getCategoryRoute($child->id)); ?>">
<h3 class="page-header item-title"><a href="<?php echo Route::_(ContentHelperRoute::getCategoryRoute($child->id, $child->language)); ?>">
<?php echo $this->escape($child->title); ?></a>
<?php if ( $this->params->get('show_cat_num_articles', 1)) : ?>
<span class="badge badge-info tip hasTooltip" title="<?php echo HTMLHelper::_('tooltipText', 'COM_CONTENT_NUM_ITEMS_TIP'); ?>">
Expand Down
2 changes: 1 addition & 1 deletion layouts/joomla/content/info_block.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<?php echo $this->sublayout('author', $displayData); ?>
<?php endif; ?>

<?php if ($displayData['params']->get('show_parent_category') && !empty($displayData['item']->parent_slug)) : ?>
<?php if ($displayData['params']->get('show_parent_category') && !empty($displayData['item']->parent_id)) : ?>
<?php echo $this->sublayout('parent_category', $displayData); ?>
<?php endif; ?>

Expand Down
7 changes: 5 additions & 2 deletions layouts/joomla/content/info_block/category.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
?>
<dd class="category-name">
<?php $title = $this->escape($displayData['item']->category_title); ?>
<?php if ($displayData['params']->get('link_category') && $displayData['item']->catslug) : ?>
<?php $url = '<a href="' . Route::_(ContentHelperRoute::getCategoryRoute($displayData['item']->catslug)) . '" itemprop="genre">' . $title . '</a>'; ?>
<?php if ($displayData['params']->get('link_category') && !empty($displayData['item']->catid)) : ?>
<?php $url = '<a href="' . Route::_(
ContentHelperRoute::getCategoryRoute($displayData['item']->catid, $displayData['item']->category_language)
)
. '" itemprop="genre">' . $title . '</a>'; ?>
<?php echo Text::sprintf('COM_CONTENT_CATEGORY', $url); ?>
<?php else : ?>
<?php echo Text::sprintf('COM_CONTENT_CATEGORY', '<span itemprop="genre">' . $title . '</span>'); ?>
Expand Down
8 changes: 5 additions & 3 deletions layouts/joomla/content/info_block/parent_category.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@

defined('JPATH_BASE') or die;

use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;

?>
<dd class="parent-category-name">
<?php $title = $this->escape($displayData['item']->parent_title); ?>
<?php if ($displayData['params']->get('link_parent_category') && !empty($displayData['item']->parent_slug)) : ?>
<?php $url = '<a href="' . Route::_(ContentHelperRoute::getCategoryRoute($displayData['item']->parent_slug)) . '" itemprop="genre">' . $title . '</a>'; ?>
<?php if ($displayData['params']->get('link_parent_category') && !empty($displayData['item']->parent_id)) : ?>
<?php $url = '<a href="' . Route::_(
ContentHelperRoute::getCategoryRoute($displayData['item']->parent_id, $displayData['item']->parent_language)
)
. '" itemprop="genre">' . $title . '</a>'; ?>
<?php echo Text::sprintf('COM_CONTENT_PARENT', $url); ?>
<?php else : ?>
<?php echo Text::sprintf('COM_CONTENT_PARENT', '<span itemprop="genre">' . $title . '</span>'); ?>
Expand Down
6 changes: 6 additions & 0 deletions libraries/src/Component/Router/Rules/MenuRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ public function preprocess(&$query)
// Get query language
$language = isset($query['lang']) ? $query['lang'] : '*';

// Set the language to the current one when multilang is enabled and item is tagged to ALL
if (Multilanguage::isEnabled() && $language === '*')
{
$language = $this->router->app->get('language');
}

if (!isset($this->lookup[$language]))
{
$this->buildLookup($language);
Expand Down

0 comments on commit 169a8e1

Please sign in to comment.