ModuleNewsCategories in multilingual mode renders top level in fallback language
Closed this issue · 1 comments
ModuleNewsCategories renders news categories in top level in fallback language if subcategories got included.
Moving the block for including subcategories near the end of the while loop brings the correct functionality.
protected function renderNewsCategories($intPid, $arrIds, $strUrl, $intLevel=1)
Code before:
while ($objCategories->next()) {
$strSubcategories = '';
// Get the subcategories
if ($objCategories->subcategories) {
$strSubcategories = $this->renderNewsCategories($objCategories->id, $arrIds, $strUrl, $intLevel);
}`
Code after moving block:
// Render categories
while ($objCategories->next()) {
$strSubcategories = '';
$blnActive = ($this->objActiveCategory !== null) && ($this->objActiveCategory->id == $objCategories->id);
$strClass = ('news_category_' . $objCategories->id) . ($objCategories->cssClass ? (' ' . $objCategories->cssClass) : '') . ((++$count == 1) ? ' first' : '') . (($count == $total) ? ' last' : '') . ((($count % 2) == 0) ? ' odd' : ' even') . ($blnActive ? ' active' : '') . (($strSubcategories != '') ? ' submenu' : '') . (in_array($objCategories->id, $this->arrCategoryTrail) ? ' trail' : '') . (in_array($objCategories->id, $this->activeNewsCategories) ? ' news_trail' : '');
$strTitle = $objCategories->frontendTitle ?: $objCategories->title;
$arrRow = $objCategories->row();
$arrRow['isActive'] = $blnActive;
$arrRow['class'] = $strClass;
$arrRow['title'] = specialchars($strTitle, true);
$arrRow['linkTitle'] = specialchars($strTitle, true);
$arrRow['link'] = $strTitle;
$arrRow['href'] = ampersand(sprintf(urldecode($strUrl), ($GLOBALS['TL_CONFIG']['disableAlias'] ? $objCategories->id : $objCategories->alias)));
$arrRow['quantity'] = 0;
// Get the news quantity
if ($this->news_showQuantity) {
$arrRow['quantity'] = \NewsModel::countPublishedByCategoryAndPids($this->news_archives, $objCategories->id);
}
// Get the subcategories
if ($objCategories->subcategories) {
$strSubcategories = $this->renderNewsCategories($objCategories->id, $arrIds, $strUrl, $intLevel);
}
$arrRow['subitems'] = $strSubcategories;
$arrCategories[] = $arrRow;
}`
Maybe it is a referencing issue of the object as it gets originally passed by the reversing function.
The issue wasn't produced by the marked error as noted.
If in templates the object model needs to be used with mutlilingual featues it has to be initiated like
$strClass = \NewsCategories\NewsCategories::getModelClass(); $objNewsCategory = $strClass::findBy(
Using \NewsCategoryModel::findBy directly instead will produce the noted behaviour above.