New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
$page->update() fills missing fields with empty values or copies main language values, ignoring blueprint settings #1571
Comments
I can confirm this and I needed it to be fixed asap because I currently rely on this to work. I found the problem to be within the For anyone in need of a quick fix: $form = Form::for($this, [
'input' => $input,
'ignoreDisabled' => $validate === false,
+ 'languageCode' => $languageCode,
]); https://github.com/getkirby/kirby/blob/master/src/Cms/Form.php#L24 - $isDefaultLanguage = $kirby->language()->isDefault();
+ $languageCode = $props['languageCode'] ?? $kirby->language()->code();
+ $isDefaultLanguage = $languageCode === $kirby->defaultLanguage()->code(); @bastianallgeier I can prepare a PR if you like. At least on first sight it seems to be an easy fix. |
@lukaskleinschmidt that would be great! |
This lukaskleinschmidt@b02b7ff fixes the issue partly. I just tried it and the This means that in my example above, If I provide |
That same thing happens if I use the panel too, by the way. If I edit a page in Bulgarian that does not have a I don't know that's the intended behavior by the devs, but it might not be the expected one. If I edit a field in another language, and see that the other fields have the same values (Kirby panel visualizes missing translated values by showing the default language ones), I expect those values to continue to be synchronized. If not that, in the API, I definitely expect |
As far as I can tell the copy of all values is currently intended and therefore expected behaviour. |
The copy of values in the panel - yes, I think that can be expected. You edit the page in the default language, then switch to another language and by editing and then saving those changes, you commit that the translation should no longer be synchronized with the default values. But in the API, I think that this behavior should be different. At least it should be controlled via an argument. It would open more possibilities for plugin devs. I currently am developing a plugin that would benefit greatly from a functionality like that. If I have a translation for a given value, I want to use it. If I don't, I want a fallback to the latest default value. |
I did not try it but does the same happen if you use the |
If I use $page->save([
'title' => 'New Title',
'description' => null
]); I would get the following in my
|
I get the desired behavior if I use |
✅ |
We should reopen this issue because now, there are issues in structures. Non-translatable fields should be skipped, but not when in structures. I have the following fields:
text:
type: text
textConst:
type: text
translate: false
test:
type: structure
fields:
text:
type: text
textConst:
type: text
translate: false ...and the following
Then, I update the Bulgarian translation with the values
As you can see, the var_dump($site->test()->toStructure()->first()->text()->value()); // "fooBG"
var_dump($site->test()->toStructure()->first()->textConst()->value()); // null At the same time, that value is grayed out in the panel and you can't fill it: What's interesting is that even if I add I see two solutions for that:
I'm currently working on a plugin that traverses the page blueprints and synchronizes structures according to them. For the most part, it works great, but it fails when it tries to copy values from the default translation - they are lost in the |
@hdodov Can you create a new one by referencing this issue please? |
The
$page->update()
method fills in the missing fields from its input with empty values or duplicates those of the main language file, ignoringtranslate: false
.The
$file->update()
method has the same problem.Steps to reproduce the behavior:
page.en.txt
:and blueprint:
title
value of that page in another language:page.bg.txt
(the secondary language file) and you'll see thetitle
field updated, but also thedescription
andcolor
(which hastranslate: false
) are copied from the main language file:This problem occurs even if I provide
null
fordescription
andcolor
and/or use the third parameter ofupdate()
for validation.Expected behavior
The
update()
method should create the secondary language file, but only populate thetitle
field:Why?
Because if
description
exists inpage.bg.txt
, it will no longer be synced with the English version as it should. Since the panel admin did not provide any value and the call toupdate()
as well, it should be the same as the default language value. If non-existent inpage.bg.txt
, Kirby will use the value inpage.en.txt
as expected.The same problem exists for
color
except it's worse. Since the field hastranslate: false
, you can't change the value in the panel and because there's a value inpage.bg.txt
, any changes topage.en.txt
will not be reflected. This means that the value in both languages will be different, defeating the purpose oftranslate: false
.Kirby Version
3.0.3
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: