The breadcrumbs->add() method:
/**
* Add a named route to the trail.
*
* @param string $title Name to display on this route's link
* @param string $route URL relative to the trail's BaseURL
* @param array $params Additional URL params to append to the route
* @return self
*/
public function add(string $title, string $route = '', array $params = [])
In use:
$page->breadcrumbs
->add(__('Manage Users'), 'user_manage.php')
->add(__('Add User'));
A few notes:
- The title for each breadcrumb should be wrapped in __() for translation.
- The home breadcrumb is automatically added.
- The module entry point is automatically added, no need for the second
getModuleEntry()
breadcrumb. - The module portion of the URL (eg: index.php?q=/modules/User Admin/) isn't needed: this is automatiaclly added.
- The final breadcrumb (
trailEnd
) doesnt need a url. - The
__()
function no longer requires a$guid
so these can be removed eg:__($guid, 'Foo')
to__('Foo')
New note:
- Delete actions are now handled with a modal window, so the breadcrumbs for these can be removed rather than refactored.
echo "<div class='trail'>";
echo "<div class='trailHead'><a href='".$_SESSION[$guid]['absoluteURL']."'>".__($guid, 'Home')."</a> > <a href='".$_SESSION[$guid]['absoluteURL'].'/index.php?q=/modules/'.getModuleName($_GET['q']).'/'.getModuleEntry($_GET['q'], $connection2, $guid)."'>".__($guid, getModuleName($_GET['q']))."</a> > </div><div class='trailEnd'>".__($guid, 'Manage Staff').'</div>';
echo '</div>';
Refactored:
$page->breadcrumbs->add(__('Manage Staff'));
echo "<div class='trail'>";
echo "<div class='trailHead'><a href='".$_SESSION[$guid]['absoluteURL']."'>".__($guid, 'Home')."</a> > <a href='".$_SESSION[$guid]['absoluteURL'].'/index.php?q=/modules/'.getModuleName($_GET['q']).'/'.getModuleEntry($_GET['q'], $connection2, $guid)."'>".__($guid, getModuleName($_GET['q']))."</a> > <a href='".$_SESSION[$guid]['absoluteURL'].'/index.php?q=/modules/'.getModuleName($_GET['q']).'/tt.php&gibbonSchoolYearID='.$_GET['gibbonSchoolYearID']."'>".__($guid, 'Manage Timetables')."</a> > <a href='".$_SESSION[$guid]['absoluteURL'].'/index.php?q=/modules/'.getModuleName($_GET['q'])."/tt_edit.php&gibbonTTID=$gibbonTTID&gibbonSchoolYearID=".$_GET['gibbonSchoolYearID']."'>".__($guid, 'Edit Timetable')."</a> > <a href='".$_SESSION[$guid]['absoluteURL'].'/index.php?q=/modules/'.getModuleName($_GET['q'])."/tt_edit_day_edit.php&gibbonTTDayID=$gibbonTTDayID&gibbonTTID=$gibbonTTID&gibbonSchoolYearID=$gibbonSchoolYearID'>".__($guid, 'Edit Timetable Day')."</a> > </div><div class='trailEnd'>".__($guid, 'Classes in Period').'</div>';
echo '</div>';
Refactored:
$urlParams = ['gibbonSchoolYearID' => $gibbonSchoolYearID, 'gibbonTTID' => $gibbonTTID, 'gibbonTTDayID' => $gibbonTTDayID];
$page->breadcrumbs
->add(__('Manage Timetables'), 'tt.php', $urlParams)
->add(__('Edit Timetable'), 'tt_edit.php', $urlParams)
->add(__('Edit Timetable Day'), 'tt_edit_day_edit.php', $urlParams)
->add(__('Classes in Period'));