Skip to content

A free open source IT asset/license management system

Fixes #9037 - Added breadcrumbs to top breadcrumb trail

snipe392af4f127d4
diff --git a/app/Providers/BreadcrumbsServiceProvider.php b/app/Providers/BreadcrumbsServiceProvider.php
index 502b7a486d..7dbb006497 100644
--- a/app/Providers/BreadcrumbsServiceProvider.php
+++ b/app/Providers/BreadcrumbsServiceProvider.php
@@ -342,14 +342,16 @@ class BreadcrumbsServiceProvider extends ServiceProvider
->push(trans('admin/locations/table.clone'), route('locations.create'))
);
- Breadcrumbs::for('locations.show', fn (Trail $trail, Location $location) => $trail->parent('locations.index', route('locations.index'))
- ->push($location->name, route('locations.show', $location))
- );
+ Breadcrumbs::for('locations.show', function (Trail $trail, Location $location) {
+ $trail->parent('locations.index', route('locations.index'));
+ $this->pushLocationHierarchy($trail, $location);
+ });
- Breadcrumbs::for('locations.edit', fn (Trail $trail, Location $location) => $trail->parent('locations.index', route('locations.index'))
- ->push($location->display_name, route('locations.show', $location))
- ->push(trans('general.update'))
- );
+ Breadcrumbs::for('locations.edit', function (Trail $trail, Location $location) {
+ $trail->parent('locations.index', route('locations.index'));
+ $this->pushLocationHierarchy($trail, $location);
+ $trail->push(trans('general.update'));
+ });
/**
* Maintenances Breadcrumbs
@@ -510,4 +512,22 @@ class BreadcrumbsServiceProvider extends ServiceProvider
);
}
+
+ /**
+ * Append parent -> child location breadcrumbs recursively for a location.
+ */
+ private function pushLocationHierarchy(Trail $trail, Location $location): void
+ {
+ $ancestorChain = [];
+ $cursor = $location;
+
+ while ($cursor !== null) {
+ array_unshift($ancestorChain, $cursor);
+ $cursor = $cursor->parent;
+ }
+
+ foreach ($ancestorChain as $node) {
+ $trail->push($node->name, route('locations.show', $node));
+ }
+ }
}
diff --git a/resources/views/locations/edit.blade.php b/resources/views/locations/edit.blade.php
index 0fa633bd8e..a6cbc32ff7 100755
--- a/resources/views/locations/edit.blade.php
+++ b/resources/views/locations/edit.blade.php
@@ -2,8 +2,6 @@
'createText' => trans('admin/locations/table.create') ,
'updateText' => trans('admin/locations/table.update'),
'topSubmit' => true,
- 'helpPosition' => 'right',
- 'helpText' => trans('admin/locations/table.about_locations'),
'formAction' => (isset($item->id)) ? route('locations.update', ['location' => $item->id]) : route('locations.store'),
])
diff --git a/tests/Feature/Locations/Ui/ShowLocationTest.php b/tests/Feature/Locations/Ui/ShowLocationTest.php
index 8d54541a3b..9f6db9ae97 100644
--- a/tests/Feature/Locations/Ui/ShowLocationTest.php
+++ b/tests/Feature/Locations/Ui/ShowLocationTest.php
@@ -37,4 +37,26 @@ class ShowLocationTest extends TestCase
->get(route('locations.print_all_assigned', Location::factory()->create()))
->assertOk();
}
+
+ public function test_show_page_includes_parent_location_breadcrumb_hierarchy()
+ {
+ $grandparent = Location::factory()->create(['name' => 'Grandparent Breadcrumb Location']);
+ $parent = Location::factory()->create([
+ 'name' => 'Parent Breadcrumb Location',
+ 'parent_id' => $grandparent->id,
+ ]);
+ $child = Location::factory()->create([
+ 'name' => 'Child Breadcrumb Location',
+ 'parent_id' => $parent->id,
+ ]);
+
+ $this->actingAs(User::factory()->superuser()->create())
+ ->get(route('locations.show', $child))
+ ->assertOk()
+ ->assertSeeInOrder([
+ route('locations.show', $grandparent),
+ route('locations.show', $parent),
+ route('locations.show', $child),
+ ]);
+ }
}
diff --git a/tests/Feature/Locations/Ui/UpdateLocationsTest.php b/tests/Feature/Locations/Ui/UpdateLocationsTest.php
index d6bce14aa5..c00ecaf0de 100644
--- a/tests/Feature/Locations/Ui/UpdateLocationsTest.php
+++ b/tests/Feature/Locations/Ui/UpdateLocationsTest.php
@@ -105,4 +105,27 @@ class UpdateLocationsTest extends TestCase
// Storage::disk('local')->assertExists($logentry->filename);
}
+
+ public function test_edit_page_includes_parent_location_breadcrumb_hierarchy()
+ {
+ $grandparent = Location::factory()->create(['name' => 'Grandparent Edit Breadcrumb Location']);
+ $parent = Location::factory()->create([
+ 'name' => 'Parent Edit Breadcrumb Location',
+ 'parent_id' => $grandparent->id,
+ ]);
+ $child = Location::factory()->create([
+ 'name' => 'Child Edit Breadcrumb Location',
+ 'parent_id' => $parent->id,
+ ]);
+
+ $this->actingAs(User::factory()->superuser()->create())
+ ->get(route('locations.edit', $child))
+ ->assertOk()
+ ->assertSeeInOrder([
+ route('locations.show', $grandparent),
+ route('locations.show', $parent),
+ route('locations.show', $child),
+ trans('general.update'),
+ ]);
+ }
}