Add method Header::isMenuEnabled()
The property Header::$isMenuEnabled shouldn't be set in constructor as this does not allow instanciating Header before connecting to the database server. Signed-off-by: Maurício Meneghini Fauth <mauricio@mfauth.net>
This commit is contained in:
parent
7bfb1dde0f
commit
34a4e668e0
@ -7149,7 +7149,7 @@ parameters:
|
||||
Use dependency injection instead\.$#
|
||||
'''
|
||||
identifier: staticMethod.deprecated
|
||||
count: 3
|
||||
count: 4
|
||||
path: src/Header.php
|
||||
|
||||
-
|
||||
|
||||
@ -4767,6 +4767,7 @@
|
||||
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
|
||||
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
|
||||
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
|
||||
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
|
||||
</DeprecatedMethod>
|
||||
<MixedAssignment>
|
||||
<code><![CDATA[$pftext]]></code>
|
||||
|
||||
@ -46,10 +46,10 @@ class Header
|
||||
* The value for the id attribute for the body tag
|
||||
*/
|
||||
private string $bodyId = '';
|
||||
/**
|
||||
* Whether to show the top menu
|
||||
*/
|
||||
private bool $menuEnabled;
|
||||
|
||||
/** Whether to show the top menu */
|
||||
private bool|null $isMenuEnabled = null;
|
||||
|
||||
/**
|
||||
* Whether to show the warnings
|
||||
*/
|
||||
@ -65,7 +65,6 @@ class Header
|
||||
private readonly Config $config,
|
||||
) {
|
||||
$dbi = DatabaseInterface::getInstance();
|
||||
$this->menuEnabled = $dbi->isConnected();
|
||||
$relation = new Relation($dbi);
|
||||
$this->menu = new Menu($dbi, $this->template, $this->config, $relation, Current::$database, Current::$table);
|
||||
$this->scripts = new Scripts($this->template);
|
||||
@ -74,6 +73,18 @@ class Header
|
||||
$this->userPreferences = new UserPreferences($dbi, $relation, $this->template);
|
||||
}
|
||||
|
||||
private function isMenuEnabled(): bool
|
||||
{
|
||||
if ($this->isMenuEnabled !== null) {
|
||||
return $this->isMenuEnabled;
|
||||
}
|
||||
|
||||
$dbi = DatabaseInterface::getInstance();
|
||||
$this->isMenuEnabled = $dbi->isConnected();
|
||||
|
||||
return $this->isMenuEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads common scripts
|
||||
*/
|
||||
@ -193,7 +204,7 @@ class Header
|
||||
*/
|
||||
public function disableMenuAndConsole(): void
|
||||
{
|
||||
$this->menuEnabled = false;
|
||||
$this->isMenuEnabled = false;
|
||||
$this->console->disable();
|
||||
}
|
||||
|
||||
@ -246,7 +257,7 @@ class Header
|
||||
$this->scripts->addFiles($this->console->getScripts());
|
||||
|
||||
$dbi = DatabaseInterface::getInstance();
|
||||
if ($this->menuEnabled && Current::$server > 0) {
|
||||
if ($this->isMenuEnabled() && Current::$server > 0) {
|
||||
$navigation = (new Navigation($this->template, new Relation($dbi), $dbi, $this->config))->getDisplay();
|
||||
}
|
||||
|
||||
@ -260,7 +271,7 @@ class Header
|
||||
$loadUserPreferences = $this->userPreferences->autoloadGetHeader();
|
||||
}
|
||||
|
||||
if ($this->menuEnabled && Current::$server > 0) {
|
||||
if ($this->isMenuEnabled() && Current::$server > 0) {
|
||||
$menu = $this->menu->getDisplay();
|
||||
}
|
||||
|
||||
@ -284,7 +295,7 @@ class Header
|
||||
'load_user_preferences' => $loadUserPreferences ?? '',
|
||||
'show_hint' => $this->config->settings['ShowHint'],
|
||||
'is_warnings_enabled' => $this->warningsEnabled,
|
||||
'is_menu_enabled' => $this->menuEnabled,
|
||||
'is_menu_enabled' => $this->isMenuEnabled(),
|
||||
'is_logged_in' => $isLoggedIn,
|
||||
'menu' => $menu ?? '',
|
||||
'console' => $console,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user