getkirby / kirby

Kirby's core application folder
https://getkirby.com
Other
1.32k stars 168 forks source link

page->update() resets select fields with query options in second language #4149

Closed mheuschneider closed 2 years ago

mheuschneider commented 2 years ago

Description

When using $page->update([], 'de'), the content should not change. But if I try the same with 'en' (second language) all select fields with a query are reseted.

The query for this select field is following: site.magazin_categories.split

Im using this function inside the page.changeSlug:after hook.

Expected behavior
The same as in the default language.

Screenshots
Screenshots after hook

de.txt image

en.txt image

To reproduce

  1. Create a custom hook:
    
    <?php

Kirby::plugin('my/customhook', [ 'hooks' => [ 'page.changeSlug:after' => function ($newPage, $oldPage) { $site = site();

        $site->page('*path/to/page*')->update(array(), 'en');
    }
]

]);

2. Replace path with a page and 'en' with secondary language
3. Create an select field (with query) for this page:
```yml
fields:
    category:
        label: Category
        type: select
        options: query
        query: site.categories.split
        width: 1/3
  1. Create an settings field for site:
    fields:
    categories:
        label: Magazin categories
        type: tags
  2. Add random category tags (in both languages)
  3. Go to page and select one tag (in both languages)
  4. Save and switch to main language
  5. Change the slug of a page (could be a different one)

Your setup

Kirby Version
Tested with 3.6.1.1 and 3.6.2

Your system

afbora commented 2 years ago

Clue about issue

I've tracked down and found that this is related with following line: https://github.com/getkirby/kirby/blob/3.6.2/src/Cms/ModelWithContent.php#L600-L604

You can simply test with following code:

$page = page('sandbox');

$form = Form::for($page, [
    'ignoreDisabled' => false,
    'input'          => [],
    'language'       => 'de', // secondary language code
]);

var_dump($form->data());

When the select field is query, its value returns empty.

afbora commented 2 years ago

Summary

Model's language data is not processed when pulling/handling query options. This issue applies to all fields that use options mixin.

https://github.com/getkirby/kirby/blob/3.6.2/config/fields/mixins/options.php#L32-L46

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.