Skip to content

Commit

Permalink
Update Multilanguage.php
Browse files Browse the repository at this point in the history
  • Loading branch information
Denitz committed Sep 22, 2023
1 parent 7df4f37 commit f56028c
Showing 1 changed file with 19 additions and 27 deletions.
46 changes: 19 additions & 27 deletions libraries/src/Language/Multilanguage.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Factory;
use Joomla\CMS\Menu\SiteMenu;
use Joomla\Database\DatabaseInterface;

// phpcs:disable PSR1.Files.SideEffects
Expand Down Expand Up @@ -89,38 +90,29 @@ public static function isEnabled(CMSApplication $app = null, DatabaseInterface $
/**
* Method to return a list of language home page menu items.
*
* @param ?DatabaseInterface $db The database
*
* @return array of menu objects.
*
* @since 3.5
*/
public static function getSiteHomePages(DatabaseInterface $db = null)
public static function getSiteHomePages()
{
// To avoid doing duplicate database queries.
static $multilangSiteHomePages = null;

if (!isset($multilangSiteHomePages)) {
// Check for Home pages languages.
$db = $db ?: Factory::getDbo();
$query = $db->getQuery(true)
->select(
[
$db->quoteName('language'),
$db->quoteName('id'),
]
)
->from($db->quoteName('#__menu'))
->where(
[
$db->quoteName('home') . ' = ' . $db->quote('1'),
$db->quoteName('published') . ' = 1',
$db->quoteName('client_id') . ' = 0',
]
);
$db->setQuery($query);

$multilangSiteHomePages = $db->loadObjectList('language');
// To avoid doing duplicate discover.
static $multilangSiteHomePages;

if ($multilangSiteHomePages === null) {
$multilangSiteHomePages = [];

// Get all site homepages.
/** @var SiteMenu $menu */
$menu = Factory::getApplication()->getMenu('site');
$items = $menu->getItems(['home', 'language', 'access'], [1, null, null]);

foreach ($items as $item) {
$multilangSiteHomePages[$item->language] = (object) [
'language' => $item->language,
'id' => $item->id,
];
}
}

return $multilangSiteHomePages;
Expand Down

0 comments on commit f56028c

Please sign in to comment.