Open neildaniels opened 4 years ago
If I remember correctly, overriding the API routes should work: https://getkirby.com/docs/reference/plugins/extensions/api#custom-endpoints
@lukasbestle I could not get get site/search
to be overridden. Neither as a plugin nor directly in my config.php
file.
Plugin example. (The die()
call will never be executed and the standard search will still occur.)
Kirby::plugin('sitesearch/test', [
'api' => [
'routes' => function ($kirby) {
return [
[
'pattern' => 'site/search',
'method' => 'GET|POST',
'action' => function () {
die("Test");
return $this->site()->children();
}
],
];
},
],
]);
This would be expected based on my understanding of how Kirby\Http\Router
works. It uses the first matching pattern route. System-default routes are "loaded" before any custom routes can be used, so it seems impossible to correctly override this behavior.
You are right, the extension routes are merged after the system API routes. Now that I think about it, that's probably on purpose to prevent plugins from breaking the Panel.
But this means that there needs to be a different solution to customize the Panel search.
@neildaniels what you could do as a workaround right now:
Extend the k-search
Vue component and only overwrite the types
computed property with your own custom endpoints:
https://github.com/getkirby/kirby/blob/master/panel/src/components/Navigation/Search.vue#L71-L90
panel.plugin("your/search", {
components: {
"k-search": {
extends: "k-search",
computed: {
types() {
...
}
}
}
});
I just discussed this with @distantnative and the search component is really intended to overwrite the search filter for collections. It's not meant to replace the entire
site()->index()
logic. If you want to do that you can replace the API route with a custom one and make sure that you run your own search logic in there. But we've added to our todo list to find a better global way of handling search in general in a later release.Originally posted by @bastianallgeier in https://github.com/getkirby/ideas/issues/570#issuecomment-652926392
This makes sense, but
api
routes cannot be overridden currently, making this seem infeasible.https://github.com/getkirby/kirby/blob/de728405c3c4813fcad6dd2361ffa373b97d688b/config/routes.php#L24-L48
https://github.com/getkirby/kirby/blob/de728405c3c4813fcad6dd2361ffa373b97d688b/src/Cms/App.php#L1166-L1177