Trigger custom field-refresh after changing the page slug

Hi, I like to display the new slug in my custom field, after the slug was changed. At the moment the field updates only after a hard page refresh.

Can I somehow trigger a custom-field-method from the page.changeSlug:after Hook?


Kirby::plugin('my/plugin',  [
    'hooks' => [
        'page.changeSlug:after' => function ($newPage, $oldPage) {
            // trigger field method here????
        },
    ], 
    'fields' => [
        'pageurls' => [
            'props' => [
                'label' => function (string $label) {
                    return $label;
                },
            ],
            'computed' => [
                'urls' => function () {
...

How can I do this?

Is this on the Kirby Panel UI?

Not quite sure what you are doing in your field. But it think you should update tithe page’s field value in your hook. Or have you already tried that?

@ahmetbora: Yes, it´s in the Kirby Panel UI.

@texnixe: how would i do that?

here´s a image of the field:

Like this:

    'page.changeSlug:after' => function ($newPage, $oldPage) {
        $newPage->update(['fieldname' => $newPage->slug()]);
      }

This should immediately show the new value. I don’t know how the data is stored in your field, you might have to adapt the code, also, since this looks you are using a multilange site, you would have to pass the language code as second parameter if you want to update other languages then the default language (might not be intended in this case).

1 Like

@texnixe: Thank you! I could rewrite the field with your provided information.