when i clone a webform programmatically i loose the translation.
This is my code.

//Load webform to duplicate
  $webform = \Drupal::entityTypeManager()->getStorage('webform')->load($default_template);

  //Create duplicate
  $webform_duplicate = $webform->createDuplicate();

  // $webform_duplicate->set('langcode','en');
  $webform_duplicate->set('description','Event Registration GR Form for '.$title);

  //Save duplicate

Webform is created with out any problems but there is no translation and when i check in the config db table there is nothing there too.
When i search for the template i can see that there is a config row-record / collection : language.el that corresponds to the translated version of the default template. I tried to add programmatically a translation with this code

  $result = \Drupal::database()->select('config', 'c')
  ->fields('c', ['collection', 'name', 'data'])
  ->condition('c.name', 'webform.webform.event_registration_gr')
  ->condition('c.collection', 'language.el', 'LIKE')

  while ($record = $result->fetchAssoc()) {
    $record['name'] = 'webform.webform.' . $webform_duplicate->id();
      ->fields(['collection', 'name', 'data'])

Which works fine too but there is an important issue with caches. If i do not run drush cr there is no translation for my webform. What am i missing here? Please can you help? Thank you in advance!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.