diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2e2381d..2621be9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Fixed
- Alerts of a child entity are displayed on the central page, the helpdesk, the service catalog and above the ticket list
+- Login form shifted to the left when no alert is displayed on the login page
## [1.15.1] - 2026-11-05
diff --git a/templates/alerts.html.twig b/templates/alerts.html.twig
index ec15f2e..2686937 100644
--- a/templates/alerts.html.twig
+++ b/templates/alerts.html.twig
@@ -50,7 +50,9 @@
{% endset %}
-{% if wrapper == 'central' %}
+{% if wrapper == 'login' and alerts is empty %}
+ {# Empty login wrapper would still reserve its fixed width next to the login form #}
+{% elseif wrapper == 'central' %}
| {{ alerts_html }} |
{% elseif wrapper == 'list' %}
| {{ alerts_html }} |
@@ -61,7 +63,7 @@
{{ alerts_html }}
{% endif %}
-{% if load_script %}
+{% if load_script and alerts is not empty %}
{{ call('Html::script', ['/plugins/news/js/news.js'])|raw }}
{% endif %}
diff --git a/tests/units/PluginNewsDisplayTest.php b/tests/units/PluginNewsDisplayTest.php
index bd9b240..cf5e589 100644
--- a/tests/units/PluginNewsDisplayTest.php
+++ b/tests/units/PluginNewsDisplayTest.php
@@ -40,9 +40,9 @@
class PluginNewsDisplayTest extends DbTestCase
{
- private function createAlert(string $name): PluginNewsAlert
+ private function createAlert(string $name, array $fields = []): PluginNewsAlert
{
- $alert = $this->createItem(PluginNewsAlert::class, [
+ $alert = $this->createItem(PluginNewsAlert::class, $fields + [
'name' => $name,
'message' => 'Alert message',
'type' => PluginNewsAlert::GENERAL,
@@ -94,6 +94,32 @@ public function testCentralContainerIsEmptyWithoutAlert(): void
$this->assertStringContainsString('', $output);
}
+ private function getLoginAlertsOutput(): string
+ {
+ ob_start();
+ PluginNewsAlert::displayOnLogin();
+
+ return (string) ob_get_clean();
+ }
+
+ public function testLoginOutputIsEmptyWithoutAlert(): void
+ {
+ $this->createAlert('Central only alert');
+
+ $this->assertSame('', trim($this->getLoginAlertsOutput()));
+ }
+
+ public function testLoginAlertIsDisplayed(): void
+ {
+ $this->createAlert('Login alert', ['is_displayed_onlogin' => 1]);
+
+ $output = $this->getLoginAlertsOutput();
+
+ $this->assertStringContainsString('', $output);
+ $this->assertStringContainsString('Login alert', $output);
+ $this->assertStringContainsString('news.js', $output);
+ }
+
public function testCentralAlertIsDisplayedToTargetedProfiles(): void
{
$this->login('glpi');