Skip to content

Commit c6c914e

Browse files
authored
[5.4] Use database from container and fix menuType table instantiation (joomla#45890)
Fix issue joomla#45886
1 parent d1bb7e6 commit c6c914e

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

administrator/modules/mod_menu/src/Dispatcher/Dispatcher.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
namespace Joomla\Module\Menu\Administrator\Dispatcher;
1212

1313
use Joomla\CMS\Dispatcher\AbstractModuleDispatcher;
14+
use Joomla\CMS\Factory;
15+
use Joomla\Database\DatabaseInterface;
1416
use Joomla\Module\Menu\Administrator\Menu\CssMenu;
1517

1618
// phpcs:disable PSR1.Files.SideEffects
@@ -33,11 +35,12 @@ class Dispatcher extends AbstractModuleDispatcher
3335
*/
3436
protected function getLayoutData()
3537
{
38+
$db = Factory::getContainer()->get(DatabaseInterface::class);
3639
$data = parent::getLayoutData();
3740

3841
$data['enabled'] = !$data['app']->getInput()->getBool('hidemainmenu');
3942

40-
$data['menu'] = new CssMenu($data['app']);
43+
$data['menu'] = new CssMenu($data['app'], $db);
4144
$data['root'] = $data['menu']->load($data['params'], $data['enabled']);
4245
$data['root']->level = 0;
4346

administrator/modules/mod_menu/src/Menu/CssMenu.php

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@
1313
use Joomla\CMS\Application\CMSApplication;
1414
use Joomla\CMS\Component\ComponentHelper;
1515
use Joomla\CMS\Event\Menu\PreprocessMenuItemsEvent;
16+
use Joomla\CMS\Factory;
1617
use Joomla\CMS\Language\Associations;
1718
use Joomla\CMS\Language\Text;
1819
use Joomla\CMS\Menu\AdministratorMenuItem;
1920
use Joomla\CMS\Uri\Uri;
2021
use Joomla\Component\Menus\Administrator\Helper\MenusHelper;
22+
use Joomla\Database\DatabaseAwareInterface;
23+
use Joomla\Database\DatabaseAwareTrait;
24+
use Joomla\Database\DatabaseInterface;
2125
use Joomla\Registry\Registry;
2226
use Joomla\Utilities\ArrayHelper;
2327

@@ -30,8 +34,10 @@
3034
*
3135
* @since 1.5
3236
*/
33-
class CssMenu
37+
class CssMenu implements DatabaseAwareInterface
3438
{
39+
use DatabaseAwareTrait;
40+
3541
/**
3642
* The root of the menu
3743
*
@@ -89,12 +95,24 @@ class CssMenu
8995
/**
9096
* CssMenu constructor.
9197
*
92-
* @param CMSApplication $application The application
98+
* @param CMSApplication $application The application
99+
* @param ?DatabaseInterface $db The database
93100
*
94101
* @since 4.0.0
95102
*/
96-
public function __construct(CMSApplication $application)
103+
public function __construct(CMSApplication $application, ?DatabaseInterface $db = null)
97104
{
105+
if ($db === null) {
106+
@trigger_error(
107+
__CLASS__ . ': The $db parameter must be set for the constructor.',
108+
\E_USER_DEPRECATED
109+
);
110+
111+
$db = Factory::getContainer()->get(DatabaseInterface::class);
112+
}
113+
114+
$this->setDatabase($db);
115+
98116
$this->application = $application;
99117
$this->root = new AdministratorMenuItem();
100118
}
@@ -230,7 +248,7 @@ protected function check($node, Registry $params)
230248
$uri = clone Uri::getInstance();
231249
$uri->setVar('recover_menu', 1);
232250

233-
$table = $this->application->bootComponent('com_menu')->getMVCFactory()->createTable('MenuType');
251+
$table = new \Joomla\CMS\Table\MenuType($this->getDatabase());
234252
$menutype = $params->get('menutype');
235253

236254
$table->load(['menutype' => $menutype]);

0 commit comments

Comments
 (0)