Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the is_front template flag using path.matcher service #280

Merged
merged 2 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions localgov_alert_banner.module
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ function localgov_alert_banner_preprocess(&$variables) {
if ($route_name == 'entity.localgov_alert_banner.status_form') {
unset($variables['content']['content_moderation_control']);
}

// Set is_front variable.
try {
$variables['is_front'] = \Drupal::service('path.matcher')->isFrontPage();
}
catch (Exception $e) {
$variables['is_front'] = FALSE;
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions tests/src/Functional/AlertBannerBlockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ public function testAlertBannerDisplays() {
// Load the front page and check the banner is displayed.
$this->drupalGet('<front>');
$this->assertSession()->pageTextContains($alert_message);

// Check that the front page class exists.
$this->assertSession()->responseContains('localgov-alert-banner--homepage');

// Check front pages class not visible on second page.
$this->drupalGet('/admin');
$this->assertSession()->responseContains('localgov-alert-banner');
$this->assertSession()->responseNotContains('localgov-alert-banner--homepage');
}

/**
Expand Down
Loading