|
/** Return your navigation in this array */ |
|
public function getCpNavItem(): ?array |
|
{ |
|
$subNavs = []; |
|
$navItem = [ |
|
'label' => 'AI Content', |
|
'url' => 'ai', |
|
'icon' => $this->cpNavIconPath(), |
|
]; |
|
$currentUser = Craft::$app->getUser()->getIdentity(); |
|
$subNavs['dashboard'] = [ |
|
'label' => 'Dashboard', |
|
'url' => 'ai/dashboard', |
|
]; |
|
if ($currentUser->can('ai:digest')) { |
|
$subNavs['digest'] = [ |
|
'label' => 'Email Digest', |
|
'url' => 'ai/digest', |
|
]; |
|
} |
|
if ($currentUser->can('ai:digest:prompts')) { |
|
$subNavs['digestPrompts'] = [ |
|
'label' => 'Digest Prompts', |
|
'url' => 'ai/digest/prompts', |
|
]; |
|
} |
|
if ($currentUser->can('ai:field-generation:view') || $currentUser->can('ai:field-generation:edit')) { |
|
$subNavs['prompts'] = [ |
|
'label' => 'Field Generation', |
|
'url' => 'ai/field-generation', |
|
]; |
|
} |
|
if (empty($subNavs)) { |
|
return null; |
|
} |
|
// A single sub nav item is redundant |
|
if (count($subNavs) === 1) { |
|
$subNavs = []; |
|
} |
|
$navItem = array_merge($navItem, [ |
|
'subnav' => $subNavs, |
|
]); |
|
|
|
return $navItem; |
|
} |
|
|
|
|
|
/** Add you custom routes here */ |
|
|
|
Event::on( |
|
UrlManager::class, |
|
UrlManager::EVENT_REGISTER_CP_URL_RULES, |
|
function (RegisterUrlRulesEvent $event) { |
|
Craft::debug( |
|
'UrlManager::EVENT_REGISTER_CP_URL_RULES', |
|
__METHOD__ |
|
); |
|
// Register our Control Panel routes |
|
$event->rules = array_merge( |
|
$event->rules, |
|
$this->customAdminCpRoutes() |
|
); |
|
} |
|
); |
|
|
|
|
|
/** Configure custom routes |
|
|
|
You can see I'm relying on a few controllers to handle |
|
the view of specific pages */ |
|
|
|
protected function customAdminCpRoutes(): array |
|
{ |
|
return [ |
|
'ai' => [ |
|
'template' => '_ai-content/cp/dashboard', |
|
], |
|
'ai/field-generation' => [ |
|
'route' => '_ai-content/field-generation/index' |
|
], |
|
'ai/digest' => [ |
|
'route' => '_ai-content/digest/index' |
|
], |
|
'ai/digest/prompts' => [ |
|
'route' => '_ai-content/digest/prompts' |
|
], |
|
'ai/dashboard' => [ |
|
'template' => '_ai-content/cp/dashboard', |
|
], |
|
]; |
|
} |