Skip to content

Commit

Permalink
Issue #469: Set the "Home" breadcrumb link text to the site name
Browse files Browse the repository at this point in the history
  • Loading branch information
lkmorlan committed May 9, 2024
1 parent 8fcddb5 commit d0146a6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
13 changes: 13 additions & 0 deletions html/modules/custom/bc_dc/bc_dc.module
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,19 @@ function bc_dc_preprocess_links__toolbar_user(array &$variables): void {
}
}

/**
* Implements hook_preprocess_HOOK() for breadcrumb.
*/
function bc_dc_preprocess_breadcrumb(array &$variables): void {
// Set the "Home" breadcrumb link text to the site name.
foreach ($variables['links'] ?? [] as $key => $link) {
if ($link->getUrl()->getRouteName() === '<front>') {
$site_name = \Drupal::config('system.site')->get('name');
$variables['breadcrumb'][$key]['text'] = $site_name;
}
}
}

/**
* Implements hook_system_breadcrumb_alter().
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ public function test(): void {
// Module configuration.
// @todo Remove this section and have the config come in from config import.
//
// Set site name.
$site_name = 'Site name ' . $this->randomString();
$this->config('system.site')->set('name', $site_name)->save();
// Configure registration_role module.
$this->drupalGet('admin/people/registration-role');
$edit = [
Expand Down Expand Up @@ -419,6 +422,7 @@ public function test(): void {
$breadcrumbs = $this->xpath('//ol[@class = "breadcrumb"]/li/a');
$this->assertCount(1, $breadcrumbs, 'Page has 1 breadcrumb.');
$this->assertEquals('/', $breadcrumbs[0]->getAttribute('href'));
$this->assertEquals($site_name, $breadcrumbs[0]->getText());
// "Edit" tab does appear for data_set content type.
$this->assertSession()->elementExists('xpath', '//a[@href = "/node/2/edit"]');
// "Outline" tab does not appear for data_set content type.
Expand Down

0 comments on commit d0146a6

Please sign in to comment.