handle translations make 'en' as active always
Problem:
When we create a page with non english locale, eg) French
In module repository create method - (copied only 3 lines from it)
$fields = $this->prepareFieldsBeforeCreate($fields);
$model = $this->model->make(Arr::except($fields, $this->getReservedFields()));
$fields = $this->prepareFieldsBeforeSave($model, $fields);
HandleTranslations has the method 'prepareFieldsBeforeSaveHandleTranslations'
Its invoked twice for creation.
prepareFieldsBeforeCreate => from here we have the languages data so it works fine.
prepareFieldsBeforeSave => from here we dont have the languages and taking 'en' as active locale.
$submittedLanguages = Collection::make($fields['languages'] ?? []);
$atLeastOneLanguageIsPublished = $submittedLanguages->contains(function ($language) {
return $language['published'];
});
Spent 2 days to figure out this issue..
1 Reply
I believe passing $original_fields to prepareFieldsBeforeSave method solved the problem.
$fields = $this->prepareFieldsBeforeSave($model, $original_fields);