Programmatically change the content of the file field

I’m really sorry, but after diving a bit deeper I found that it’s not possible to solve your particular case in a non-hackish way with our field plugins at the moment.

As mentioned above, the queries in the blueprints are done on the server. Thus, you have to store the result of the gallery field first before the other fields can react to it.

This is possible in theory, but it’s not very elegant and has a couple unwanted side effects.

Here’s still how you could do this in a custom pages field.

<?php

Kirby::plugin('example/gallery', [
  'fields' => [
    'gallery' => [
      'extends' => 'pages'
    ]
  ]
]);
panel.plugin("example/gallery", {
  fields: {
    gallery: {
      extends: "k-pages-field",
      methods: {
        onInput() {
          this.$emit("input", this.selected);
          this.$store.dispatch("content/save");
        }
      }
    }
  }
});

It’s important that the field definition in the PHP file also extends the pages field. That’s why your first try didn’t work.

You can then overwrite the onInput method of the pages field component, which will be triggered whenever a selection in the pages picker is made.

When you save the content directly after such a selection, the page view will be rerendered and you get what you are looking for. But it has a nasty side effect of a flickering safe bar and also could lead to broken file relations in the files picker, if you switch the gallery.

I’m sorry I cannot provide a better solution.