octobercms/october · error · SystemException
Unable to remove navigation items before they are loaded.
Error message
Unable to remove navigation items before they are loaded.
What it means
Thrown by NavigationManager::removeMainMenuItem when the internal items collection is null, i.e. navigation has not been loaded yet. Removing a menu item before the navigation set exists is an order-of-operations error, not a 'missing item' error — no lookup is even attempted.
Solutions
- Move the removal call after navigation is loaded (e.g. inside a backend.menuExtendItems event listener)
- Ensure the code path runs during a request phase where NavigationManager has already loaded items
- Override the item in plugin registration instead of removing it at boot time
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at modules/backend/classes/NavigationManager.php:266 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of octobercms/october@b608633a7e (2026-08-21).
Data as JSON: /api/errors/9fb9795b4e4cb809.
Report an issue: GitHub.
Appendix: source
Thrown at modules/backend/classes/NavigationManager.php:266
/**
* getMainMenuItem returns a main menu item
*/
public function getMainMenuItem(string $owner, string $code): ?MainMenuItem
{
$itemKey = $this->makeItemKey($owner, $code);
return $this->items[$itemKey] ?? null;
}
/**
* removeMainMenuItem removes a single main menu item
* @param $owner
* @param $code
*/
public function removeMainMenuItem($owner, $code)
{
if ($this->items === null) {
throw new SystemException('Unable to remove navigation items before they are loaded.');
}
$itemKey = $this->makeItemKey($owner, $code);
unset($this->items[$itemKey]);
}
/**
* addSideMenuItems dynamically adds an array of side menu items
* @param string $owner
* @param string $code
* @param array $definitions
*/
public function addSideMenuItems($owner, $code, array $definitions)
{
foreach ($definitions as $sideCode => $definition) {
if (is_array($definition)) {
$this->addSideMenuItem($owner, $code, $sideCode, $definition);View on GitHub (pinned to b608633a7e)