KMP PHP API Reference

NavigationCell extends Cell
in package

Navigation cell

View Cell responsible for building and organizing the complete navigation menu structure for the KMP application. This cell handles the complex logic of organizing navigation items into hierarchical menus with proper active state detection and permission-based filtering.

The cell works with the NavigationRegistry service to collect navigation items from various plugins and core modules, then organizes them into a structured menu hierarchy with parent categories, main links, and sublinks.

Key Features:

  • Dynamic menu generation based on user permissions
  • Hierarchical organization (Parent > Child > Sublink)
  • Active state detection for current page highlighting
  • Plugin-extensible navigation system
  • Responsive menu structure support

Template: templates/cell/Navigation/display.php

Tags
see
NavigationRegistry

Navigation item collection service

Table of Contents

Properties

$_validCellOptions  : array<string, mixed>
List of valid options that can be passed into this cell's constructor.

Methods

display()  : void
Default display method for building navigation menu
initialize()  : void
Initialization logic run at the end of object construction.
getBadgeStatus()  : mixed
Get badge status.
hasBadge()  : bool
Check if has badge.
isActive()  : bool
Determine if a navigation link is active based on current request
organizeMenu()  : array<string|int, mixed>
Organize navigation items into hierarchical menu structure

Properties

$_validCellOptions

List of valid options that can be passed into this cell's constructor.

protected array<string, mixed> $_validCellOptions = []

Currently empty as this cell doesn't accept configuration options, but maintained for future extensibility.

Methods

display()

Default display method for building navigation menu

public display() : void

Collects navigation items from the NavigationRegistry based on the current user and request context, then organizes them into a hierarchical menu structure. The resulting menu includes proper active state detection and permission filtering.

Process Flow:

  1. Extract current user and request parameters
  2. Collect navigation items from registry (filtered by permissions)
  3. Organize items into hierarchical structure
  4. Set organized menu for template rendering

The menu structure returned includes:

  • Parent categories with children
  • Main navigation links
  • Sublinks under main categories
  • Active state flags for current page
Tags
see
NavigationRegistry::getNavigationItems()

Item collection

see
organizeMenu()

Menu hierarchy organization

Return values
void

Menu data is set via $this->set() for template access

initialize()

Initialization logic run at the end of object construction.

public initialize() : void

Currently no initialization required, but maintained for potential future setup needs.

getBadgeStatus()

Get badge status.

protected getBadgeStatus(mixed $badgeConfig) : mixed
Parameters
$badgeConfig : mixed

hasBadge()

Check if has badge.

protected hasBadge(mixed $link, mixed $currentRequestString) : bool
Parameters
$link : mixed
$currentRequestString : mixed
Return values
bool

isActive()

Determine if a navigation link is active based on current request

protected isActive(array<string|int, mixed> $link, string $currentRequestString) : bool

Checks if the given navigation link should be marked as active by comparing its URL and active paths against the current request string. Supports both exact matching and wildcard pattern matching for flexible active state detection.

Active State Matching:

  1. Exact URL match: Link URL exactly matches current request
  2. Active paths: Link defines specific paths that should mark it active
  3. Wildcard matching: Paths ending with '*' match URL prefixes
Parameters
$link : array<string|int, mixed>

Navigation link item with 'url' and optional 'activePaths'

$currentRequestString : string

Normalized current request path (controller/action/params)

Tags
example
// Exact match
$link = ['url' => '/members/index'];
$current = 'members/index';
// Returns: true

// Wildcard match
$link = ['url' => '/members', 'activePaths' => ['members/*']];
$current = 'members/view/123';
// Returns: true (matches wildcard pattern)

// No match
$link = ['url' => '/branches'];
$current = 'members/index';
// Returns: false
see
StaticHelpers::makePathString()

URL normalization helper

Return values
bool

True if the link should be marked as active

organizeMenu()

Organize navigation items into hierarchical menu structure

protected organizeMenu(array<string|int, mixed> $menuItems, mixed $user) : array<string|int, mixed>

Takes the flat array of navigation items from the registry and organizes them into a hierarchical structure with parents, children, and sublinks. Also handles active state detection based on the current request URL.

Menu Organization:

  • Parent items: Top-level categories (type='parent')
  • Main links: Direct children of parents (mergePath length = 1)
  • Sublinks: Third-level items under main links (mergePath length > 1)

Active State Logic:

  • Marks current page and its parent hierarchy as active
  • Uses exact URL matching and wildcard pattern matching
  • Only one active path is marked to prevent conflicts
Parameters
$menuItems : array<string|int, mixed>

Flat array of navigation items from NavigationRegistry

$user : mixed
Tags
example
// Input: Flat navigation items
[
  ['type' => 'parent', 'label' => 'Members', 'order' => 1],
  ['type' => 'link', 'label' => 'View All', 'mergePath' => ['Members'], 'url' => '/members'],
  ['type' => 'link', 'label' => 'Add Member', 'mergePath' => ['Members', 'View All'], 'url' => '/members/add']
]

// Output: Hierarchical structure
[
  'Members' => [
    'label' => 'Members',
    'active' => true,
    'children' => [
      'View All' => ['label' => 'View All', 'active' => true, 'sublinks' => [...]]
    ]
  ]
]
Return values
array<string|int, mixed>

Hierarchically organized menu structure with active states


        
On this page

Search results