Skip to content
This repository was archived by the owner on Jan 4, 2021. It is now read-only.

Allow Override for site/search Route (for customizing Panel Search) #573

Open
neildaniels opened this issue Jul 2, 2020 · 4 comments
Open

Comments

@neildaniels
Copy link

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 #570 (comment)

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

@lukasbestle
Copy link
Member

If I remember correctly, overriding the API routes should work: https://getkirby.com/docs/reference/plugins/extensions/api#custom-endpoints

@neildaniels
Copy link
Author

@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.

@lukasbestle
Copy link
Member

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.

@distantnative
Copy link
Member

distantnative commented Jul 19, 2020

@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() {
          ...
        }
    }
  }
});

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

3 participants