Problem/Motivation

When I create a translation for a web form, usually the CKEditor is shown also in the translation form of fields entered with CKEditor, e.g. text fields. However, when defining a "Custom body" in an email confirmation/notification with CKEditor (which is actually the only choice), the respective element in the translation form is shown as a plain text field with the source code.
Translation of the emails is therefore tricky for translators not aware of HTML code, and who are otherwise already used to work in CKEditor fields.

Steps to reproduce

  1. Install webform and a language for translations
  2. For example, in the contact form, go to Settings - Email/Handlers, edit one of them, under Message, select "Custom body", enter some formatted text in the CKEditor
  3. In the same webform, go to Translate, edit/add any language, under Webform Handlers, open Email...mapping, open Email: the Email body source text is displayed in a plain text field only

Proposed resolution

Enable CKEditor in the translation of the Email body text, if it is a "Custom body"

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alexh created an issue. See original summary.

jrockowitz’s picture

I am almost certain this proved to be really difficult to do because it is impossible to track when an email handler was being translated.

jrockowitz’s picture

Status: Active » Needs review
FileSize
3.21 KB

I stand corrected. Here is a POC but it is going to need a lot of improvements.

I am might learn toward adding a ::alterTranslationConfigForm method to the \Drupal\webform\Plugin\WebformHandlerInterface

alexh’s picture

Thank you for your quick response and solution.

I tested the patch and it brings up the CKEditor as expected. Fantastic, this would suffice my use case!

There is actually the same kind of issue for the Confirmation message: a CKEditor field in the form settings, but a plain text field only in the translation form. Would it be possible to change this into a CKEditor field there as well?

If this is too complicated for general implementation - would it be possible to make such changes using a custom module?

jrockowitz’s picture

@alexh. In a custom module, you can call the needed form alter hooks and alter the elements has needed.

@see webform/includes/webform.translation.inc

alexh’s picture

@jrockowitz thank you for the hint. Your patch made me aware of the 'webform_html_editor' field type. Knowing that, it was quite easy to achieve having a CKEditor in the translation form elements of the confirmation message and email confirmation message, using a custom module.

Just wanted to share my solution on the example of the default Contact form, as it might be useful for someone else:

function MYMODULE_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {

  // Contact form translation
  if (($form_id == 'config_translation_edit_form' || $form_id == 'config_translation_add_form') && isset($form['config_names']['webform.webform.contact'])) {

    // Enable CKEditor for translation of confirmation message
    $form['config_names']['webform.webform.contact']['settings']['confirmation_message']['translation']['#type'] = 'webform_html_editor';
    // Enable CKEditor for translation of email confirmation message
    $form['config_names']['webform.webform.contact']['handlers']['email_confirmation']['settings']['body']['translation']['#type'] = 'webform_html_editor';
    // Enable CKEdtior for translation of email notification message
    $form['config_names']['webform.webform.contact']['handlers']['email_notification']['settings']['body']['translation']['#type'] = 'webform_html_editor';

  }
}

For other forms, the key 'webform.webform.contact' would need to be adapted.

jrockowitz’s picture

Fixing the email handler's body is going to be tricky because it can be Twig, HTML, or a template.

Displaying an HTML Editor for the appropriate webform settings (ie. confirmation_message, error message, etc...) when a webform is translated is much easier.

@see #3204180: When translating a webform settings HTML editor should be displayed

jrockowitz’s picture

jrockowitz’s picture

Patch now has test coverage.

  • jrockowitz authored 2e3620e on 6.x
    Issue #3202515 by jrockowitz: Translation of custom body of email...
jrockowitz’s picture

Webform logo This ticket was completed using Open Collective funds.
Please consider joining the Webform module's Open Collective to help ensure that the Webform module is maintained.
jrockowitz’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.