Problem/Motivation
On a multilingual site, EditableFieldsForm::buildForm() reloads the entity fresh with $storage->load($id), which returns the default translation. It never switches to the translation of the entity the formatter
was rendered for. As a result the inline widget and the fallback formatter always show the default-language value, even when the field is translatable and the row is a different translation.
submitForm() already switches to the translation from the hidden entity_language field (fixed in #3415088), so the value is saved to the correct translation. The user then reloads the page and sees the
default-language value again, which looks like the save was lost. Right after the AJAX submit the widget still shows the typed value, so the problem only becomes visible after a page reload.
Steps to reproduce
1. Multilingual site, a node type with a translatable integer field, translations in two languages with different values.
2. A view listing nodes with rendering language set to the entity translation, showing the field with the Editable Fields formatter.
3. On a row of a non-default translation, note the displayed value: it is the default-language value.
4. Change it, click Update, reload the page: the default-language value is shown again, while the database holds the new value on the correct translation.
Proposed resolution
After the fresh load in buildForm(), switch to the translation matching the language of the entity passed to the form, when that translation exists. Do the same in ajaxCallback() for the display-mode reload, and
use hasTranslation() before getTranslation() in submitForm() so a missing translation cannot throw. Patch attached.
| Comment | File | Size | Author |
|---|---|---|---|
| editablefields.1.0.2.load-translation.patch | 1.99 KB | izabelatina |
Comments
Comment #2
angel_devoeted commentedTested
editablefields.1.0.2.load-translation.patch, but it throws aTypeErroron form build:TypeError: Drupal\editablefields\services\EditableFieldsHelper::prepareSelector(): Argument #1 ($entity) must be of type Drupal\Core\Entity\EntityInterface, null given, called in EditableFieldsForm.php on line 419In
buildForm(),$this->entityisundefined(it is passed as$entityargument).Also,
$langcodemust be captured before reloading the entity from storage:Comment #3
angel_devoeted commented