Hello I've created a new element type in a module (a web app within Craft) that I'm developing.
I have initially created my models to be craft\db\ActiveRecord
and save directly to their tables, but that is not the "craft" way.
I decided to extend from craft\base\Element
and do the needful in order to leverage elementindex.html (search, sort, filter), but going to /admin/custom/index
gives a "404 Not Found". Do I need to create my own CustomController.php ?
I did the configuration needed in my Module class, as well as creating the Custom.php and CustomQuery.php according to the documentation here
// CP Routes
Event::on(
UrlManager::class,
UrlManager::EVENT_REGISTER_CP_URL_RULES,
function (RegisterUrlRulesEvent $event) {
$event->rules['custom'] = '/app-module/custom/index';
}
);
// CP Nav Items
Event::on(
Cp::class,
Cp::EVENT_REGISTER_CP_NAV_ITEMS,
function (RegisterCpNavItemsEvent $event) {
$event->navItems[] = [
'url' => 'custom',
'label' => 'Custom',
'icon' => 'share',
];
}
);
// Custom Element Types
Event::on(Elements::class,
Elements::EVENT_REGISTER_ELEMENT_TYPES,
function(RegisterComponentTypesEvent $event) {
$event->types[] = Custom::class;
}
);