In a multilingual environment, autosave correctly remembers the form values as configured and also provides them when re-entering the unsaved form. However, saving a translated node fails if the node has a different language than the current interface language.

Env:
* D7.41
* i18n and node translation enabled

Reproduce:
* Enable autosave on a translatable node type
* Set preferred interface language to "en"
* Set language detection to all checkboxes checked (installation default)
* Find a translated node in a different language than "en"
* Wait for auto-saving
* Leave form
* Re-enter form
* Save form

Expected:
Being redirected to /[language_prefix]/node/nid

Actual behavior:
404 after being redirected to /en/[language_prefix]/node/nid/edit

Counter-check:
Disabling autosave without any other changes brings back the expected behavior.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

doitDave created an issue. See original summary.

bohemier’s picture

I'm having a similar issue: every time a form is restored, the action attribute of the form element gets changed to /en/en/node/nid/edit or /en/fr/node/nid/edit

I found the cause to be in function autosave_restore()

    // Because the form will by default submit back to this URL, we need to
    // tell it to actually submit back to where it would have submitted to
    // originally.
    $form['#action'] = **url**($record->path);

$record->path already contains the language prefix and the url function is adding another. A quick fix is to just output "/{$record->path}" but that will break some sites with an url prefix... I'm not sure if the fix should be worked here or earlier in the process...

bohemier’s picture

OK there were 2 approaches to this: either we do not save language information with the form in autosave_form_alter(), i.e. replace $request_path = request_path(); with $request_path = drupal_get_path_alias();. This approach will remove any language info from the form. Since there does not seem to be a way to get the current language upon restoring (ajax call? the $language_url global is empty and $language always reverts to default), the restored form will always point to the site's default language upon saving.

Another approach is to leave the language in the autosaved form as it is now, and change the way the form action attribute is rebuilt in autosave_restore, as suggested in my first post. This would be done by changing the call to url(), ie

$form['#action'] = base_path().$record->path;

This allows to keep the original form language. Attached is a patch that implements this second approach.

bohemier’s picture

Status: Active » Needs review

See https://www.drupal.org/project/autosave/issues/2944324 for a fix with ajax calls and language and apply both patches