🇪🇸Spain @elkiwi

Account created on 16 September 2012, over 12 years ago
#

Recent comments

🇪🇸Spain elkiwi

I have resolved this issue by using hook_form_alter. Maybe saving the form was a bad idea in the first place when there was no need to:

function MY_MODULE_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id)
{
if ($node && $node->hasField('field_villa_company')) {
      // Get the webform submission handler settings
      $handlers = $form_state->getFormObject()->getWebform()->getHandlers();
      $email_handler = $handlers->get('email');

      if ($email_handler) {
        $settings = $email_handler->getSettings();

        // Modify the to_mail based on field_villa_company value
        if ($node->get('field_villa_company')->isEmpty() || $node->get('field_villa_company')->value == '0') {
          $settings['to_mail'] = 'redacted@example.com';
        } elseif ($node->get('field_villa_company')->value == 2) {
          $settings['to_mail'] = 'redacted_2@example.com';
        } else {
          $settings['to_mail'] = 'redacted_3@example.com';
        }

        // Update the handler settings
        $email_handler->setSettings($settings);
      }
    }

//...

Now I can safely translate the webform without the English getting overwritten.

🇪🇸Spain elkiwi

I've been testing this again to try and track down where the problem lies. I rebuilt the whole form one element at a time, adding the translations one language at a time.

Then I would preview the form via the "View" tab in the Webform admin.

This all worked perfectly with all forms displaying with translations.

But as soon as I view the form on a node where it is embedded as a block, the original (English) form gets overwritten as described in my first post #1

So I'm not sure now whether there's some other custom code on our site doing this but a I see similar issues still open, I will keep watching both these threads and continue investigating.

Production build 0.71.5 2024