Searching for pages on a virtual page

Hello all, this is my first post and English is not my first language so be patient with me.

I’m trying to use a page selector on a virtual page. This is (part of) the template my virtual pages use. Right now I’m on a virtual page called “Emmalaan” which is a subpage of “Werkzaamheden”.

tabs:
  main:
    label: Algemeen
    columns:
      travelers:
        width: 2/3
        sections:
          travelers:
            type: fields
            fields:
              actions:
                label: Acties voor reizigers
                type: structure
                max: 1
                fields:
                  header:
                    label: Titel
                    type: text
                    default: Acties en tips voor reizigers
                  action_pages:
                    label: Acties en tips voor reizigers
                    type: pages
                    query: site.index.filterBy('template', 'in', ['article'])

The action_pages is where I’m having trouble. I can select a page just fine, however when i use the search functionality I get an error:

{
    "status": "error",
    "message": "The page \"werkzaamheden\/emmalaan\" cannot be found",
    "code": 404,
    "exception": "Kirby\\Exception\\NotFoundException",
    "key": "error.page.notFound",
    "file": "\/kirby\/src\/Cms\/Find.php",
    "line": 85,
    "details": [],
    "route": "pages\/([a-zA-Z0-9\\.\\-_%= \\+\\@\\(\\)]+)\/fields\/([a-zA-Z0-9\\.\\-_%= \\+\\@\\(\\)]+)(?:\/(.*))?"
}

It seems like it’s trying to reload the virtual page I’m on. But I’m not even selecting a page yet, the error pops op after pressing enter after my search query.

So for clarification, I’m not trying to add a virtual page or search for one, I’m trying to search for a regular page while on a virtual page.

I appreciatie any help :slight_smile:

Hi and welcome to the forum.

Sorry for the late reply, had to set up a test case first, but couldn’t reproduce the issue.

Could you provide the exact steps to reproduce?

Oh, wait, are you still on Kirby 3?

Hello and no worries,

We’re still on kirby 3 yes, we have an internal plugin which doesn’t work with kirby 4 (yet). But this should work with kirby 3 as well right? It seems like a weird bug with the search bar for pages in the panel.

Steps to reproduce:

  • We create virtual pages with the internal plugin
  • We use a detours page (called “Werkzaamheden”) for an overview of all detour pages (“Emmalaan” is one of those)
  • Each detour page has a blueprint, template and a controller. With the “detour” blueprint we can also add subpages. This is the code i just shared (I called it template in my my previous post but I meant blueprint).
  • These virtual pages can be accessed from within the panel and the website.
  • Whenever i edit a virtual page (by for example adding a subpage), it creates a .txt file for this page, like it’s supposed to. If I don’t edit the page it stays a virtual page and it doesn’t have a .txt file
    *Editing this page works, I can add text fields, subpages etc. The only thing which doesn’t work is using the search bar in the “action_pages” field, this happens after typing the search field:

Here is the part of the plugin where we create the pages using the Pages::factory

public function children()
    {
        if ($this->children instanceof Pages) {
            return $this->children;
        }

        $search = get('search');
        $status = get('detour_status');
        $areas = get('areas');
        $results = $this->detours($search, $status, $areas);
        $pages = [];

        foreach ($results as $key => $detour) {
            $slug = $detour['slug'];
            $page = $this->subpages()->find($slug);

            $pages[] = [
                'slug' => $detour['slug'],
                'num' => 0,
                'template' => 'detour',
                'model' => 'detour',
                'files' => $page ? $page->files()->toArray() : null,
                'content' => [
                    'title' => $detour['name'],
                    "description" => $detour['description'],
                    "detour_status" => $detour['status'],
                    "slug" => $detour['slug'],
                    "website" => $detour['website'],
                    "cover" => $detour['coverPhoto'],
                    "type" => $detour['detourType'],
                    "fases" => $detour['fases'],
                    "infraManager" => isset($detour['infraManager']) ? $detour['infraManager'] : null,
                    'uuid' => $detour['id'],
                    'actions' => $page ? $page->actions()->value() : null,
                    'employer' => $page ? $page->employer()->value() : null,
                    'logistic' => $page ? $page->logistic()->value() : null,
                ],
            ];
        }

        return $this->children = Pages::factory($pages, $this);
    }

$results is filled with data from our internal API.

Do you need anything else?

Hm, what is this search code doing in there? That’s probably causing the issue.

Wow you’re right!

We use this as a filter for our GRAPHQL query

 private function detours($search = null, $status = null, $areas = null)
 $query = <<<'GRAPHQL'
query detours($filter: DetoursFilter) {
  detours(filter:$filter) {
    detours {
     <rest of the query>
 }
}
GRAPHQL;

if (isset($search) && !empty($search)) {
    $filter['query'] = $search;
}

<rest of the code>

Thanks a lot. I’ll find a different way to filter the query.