I’m sorry for the code screenshot ;). The code is in one of plugin registration file (Plugin.php):
public function boot()
{
Event::listen('cms.page.display', function ($controller, $url, $page, $result) {
$headers = [
'Cache-Control' => 'max-age=2592000, public',
];
return ResponseFacade::make($result, $controller->getStatusCode(), $headers);
});
App::error(
function (ModelNotFoundException $exception) {
return App::make(Controller::class)
->setStatusCode(Response::HTTP_NOT_FOUND)
->run('/404');
}
);
Event::listen(
'pages.menuitem.listTypes',
function () {
return [
'section' => 'Section',
];
}
);
Event::listen(
'backend.form.extendFields',
function (Form $widget) {
if (!$widget->getController() instanceof Index || (!$widget->model instanceof StaticBackendPage && !$widget->model instanceof MenuItem)) {
return;
}
$widget->removeTab('rainlab.pages::lang.menuitem.display_tab');
$widget->removeTab('rainlab.pages::lang.menuitem.attributes_tab');
if ($widget->model instanceof StaticBackendPage) {
$widget->addTabFields(
[
'viewBag[noIndex]' => [
'tab' => 'cms::lang.editor.meta',
'label' => 'Add page to indexation?',
'type' => 'switch',
'options' => ['Yes', 'No'],
],
]
);
}
if ($widget->model instanceof MenuItem) {
$widget->addTabFields(
[
'viewBag[cssIcon]' => [
'tab' => 'Attributes',
'label' => 'Icon',
'type' => 'mediafinder',
'trigger' => [
'action' => 'show',
'field' => 'type',
'condition' => 'value[url]'
],
],
'viewBag[sectionType]' => [
'tab' => 'Attributes',
'label' => 'Section type',
'comment' => 'Please select a section type',
'type' => 'dropdown',
'default' => 'other',
'options' => [
'other' => 'Other',
'tiles' => 'Highlighted Tiles',
'icons' => 'With Icons',
],
'trigger' => [
'action' => 'show',
'field' => 'type',
'condition' => 'value[section]'
],
],
'viewBag[item_description]' => [
'tab' => 'Attributes',
'label' => 'Description',
'comment' => 'Enter a description (only appears when item is in highlighted section)',
'trigger' => [
'action' => 'hide',
'field' => 'type',
'condition' => 'value[section] || value[url]'
]
],
'viewBag[icon]' => [
'tab' => 'Attributes',
'label' => 'Icon',
'type' => 'text',
'default' => 'ico/plane.svg',
'trigger' => [
'action' => 'hide',
'field' => 'type',
'condition' => 'value[section] || value[url]',
]
]
]
);
}
;
}
);
}
If I remove the condition if ($widget->model instanceof MenuItem) {
and so on, the modal form appears afer clicking Add subitem.