Skip to content

Commit e9c172d

Browse files
Denitzrichard67QuyTonrdeutz
authored
[6.1] Improve Multilanguage::getSiteHomePages() (#41507)
--------- Co-authored-by: Richard Fath <richard67@users.noreply.github.com> Co-authored-by: Quy <quy@nomonkeybiz.com> Co-authored-by: Robert Deutz <rdeutz@googlemail.com>
1 parent 7996a3f commit e9c172d

File tree

3 files changed

+29
-31
lines changed

3 files changed

+29
-31
lines changed

libraries/src/Language/Multilanguage.php

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
use Joomla\CMS\Application\CMSApplication;
1313
use Joomla\CMS\Factory;
14+
use Joomla\CMS\Menu\MenuItem;
15+
use Joomla\CMS\Menu\SiteMenu;
1416
use Joomla\Database\DatabaseInterface;
1517

1618
// phpcs:disable PSR1.Files.SideEffects
@@ -89,40 +91,15 @@ public static function isEnabled(?CMSApplication $app = null, ?DatabaseInterface
8991
/**
9092
* Method to return a list of language home page menu items.
9193
*
92-
* @param ?DatabaseInterface $db The database
93-
*
94-
* @return array of menu objects.
94+
* @return MenuItem[] array of menu item objects.
9595
*
9696
* @since 3.5
9797
*/
98-
public static function getSiteHomePages(?DatabaseInterface $db = null)
98+
public static function getSiteHomePages()
9999
{
100-
// To avoid doing duplicate database queries.
101-
static $multilangSiteHomePages = null;
102-
103-
if (!isset($multilangSiteHomePages)) {
104-
// Check for Home pages languages.
105-
$db = $db ?: Factory::getDbo();
106-
$query = $db->createQuery()
107-
->select(
108-
[
109-
$db->quoteName('language'),
110-
$db->quoteName('id'),
111-
]
112-
)
113-
->from($db->quoteName('#__menu'))
114-
->where(
115-
[
116-
$db->quoteName('home') . ' = ' . $db->quote('1'),
117-
$db->quoteName('published') . ' = 1',
118-
$db->quoteName('client_id') . ' = 0',
119-
]
120-
);
121-
$db->setQuery($query);
122-
123-
$multilangSiteHomePages = $db->loadObjectList('language');
124-
}
100+
/** @var SiteMenu $menu */
101+
$menu = Factory::getApplication()->getMenu('site');
125102

126-
return $multilangSiteHomePages;
103+
return $menu->getHomepages();
127104
}
128105
}

libraries/src/Menu/AbstractMenu.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,27 @@ protected function getUser()
395395
: $this->storedUser;
396396
}
397397

398+
/**
399+
* Returns homepages per language.
400+
*
401+
* @return MenuItem[]
402+
*
403+
* @since __DEPLOY_VERSION__
404+
*/
405+
public function getHomepages()
406+
{
407+
// Ensure that defaults are filled.
408+
$this->getMenu();
409+
410+
$homepages = [];
411+
412+
foreach ($this->default as $language => $id) {
413+
$homepages[$language] = $this->items[$id];
414+
}
415+
416+
return $homepages;
417+
}
418+
398419
/**
399420
* Magic getter for the user object. Returns the injected
400421
* one if any, or the current one if none.

libraries/src/Menu/SiteMenu.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public function load()
191191
return false;
192192
}
193193

194-
foreach ($this->items as &$item) {
194+
foreach ($this->items as $item) {
195195
// Get parent information.
196196
$parent_tree = [];
197197

0 commit comments

Comments
 (0)