TimOetting/kirby-builder

Image select for both editor and textarea doesn't work

mynameisfreedom opened this issue ยท 7 comments

@TimOetting There is still an error when using the editor inside builder. When I select the image block inside the editor and try to select an image, I get the following error message:

Invalid file model type: kirby-builder/pages/mypage/fields

Originally posted by @RobertCordes in #132 (comment)

wout commented

We are having the same issue. And it's not only with an editor but also a textarea inside a builder:

image

Uploading an image works, but Select a file shows the modal with the error above.

Same thing here for both editor and textarea.

Kirby has this very generic files route:

[
     'pattern' => '(:all)/files',
     'method'  => 'GET',
     'action'  => function (string $path) {
         return $this->parent($path)->files()->sortBy('sort', 'asc', 'filename', 'asc');
     }
],

which wins over the one defined by the plugin:

[
  'pattern' => 'kirby-builder/pages/(:any)/fields/(:any)/(:all?)',
  'method' => 'ALL',
  'action'  => function (string $id, string $fieldPath, string $path = null) {
    if ($page = $this->page($id)) {
      return callFieldAPI($this, $fieldPath, $page, $path);
    }
  }
]

When temporarily deactivating the core route, everything works.
Unfortunately, I do not see an obvious way to overwrite / extend the core routes. Also, using the route:before hook did not help, as it was only called for the route api/(.*), and calling ->next() did not work since the $beforeEach stuff does not happen in the try-catch block of Router::call(). So, it seems that route:before can not be used to actually influence anything but rather to do some background work or die/exit.

Kirby has this very generic files route which wins over the one defined by the plugin:

wow, nice find! ๐ŸŽ‰ i am struggeling with the same thing and have been using the hack referenced here before: #110 (comment)

But this is really unstable unfortunatly.

looking into the core routes: disabling it seems to break the standard pages for files as in /panel/pages/home/files/bildschirmfoto-2020-06-16-um-16.36.28.png

but changing the route to (:all?) as in

[
     'pattern' => '(:all?)/files',
     'method'  => 'GET',
     'action'  => function (string $path) {
         return $this->parent($path)->files()->sortBy('sort', 'asc', 'filename', 'asc');
     }
],

seems to let the single pages for files work and also let the image chooser inside kirby builder work. This is just trial and error though. i dont know what the question mark does, i cant find it in the docs for routing. Do you know what that means @jonathan-reisdorf ? Might that be something that needs to change in kirby core?

BTW, i think this is the same issue as this #110

Thanks for linking these issues together. I agree that this is ideally changed in kirby's core either by making the pattern more specific or providing a way for plugin routes to be preferred over core routes. There might also be more ways to solve this. The corresponding issue getkirby/editor#175 is already flagged with type: bug by the kirby author, so he's aware :)

I can confirm changing
/kirby/config/api/routes/files
line 27
from 'pattern' => '(:all)/files',
to 'pattern' => '(:all?)/files',
seems to help. I have no idea what implications of this are BUT i badly need this to work somehow so i am running with it.

Closing this issue because this plugin will no longer be maintained, as its main functionality can be replaced by Kirby's built-in Blocks Field and Layout Field.