0

I want to override prepareTranslation method using my custom module in drupal 8. You can find this function here(Drupal\core\modules\content_translation\src\Controller\ContentTranslationController.php).

1

You can use hook_entity_prepare_form() to override the values from prepareTranslation() on $form_state.

  • Thanks for your reply. I want to change the $source_translation variable's value of prepareTranslation() function and rest of the things should work as it is in core function.i tried using below code but not geeting output. – Nikhil Valand May 26 '17 at 10:25
  • function testmodule_entity_prepare_form(\Drupal\Core\Entity\EntityInterface $entity, $operation, \Drupal\Core\Form\FormStateInterface $form_state) { $source_translation = $entity->toArray(); $source_translation['title'][0]['value'] = "Hello"; $source_translation['body'][0]['value'] = "Fine"; } – Nikhil Valand May 26 '17 at 10:26
  • $soruce_translation is available in form_state. you could change it there. that's what prepareTranslation() is doing. – vijaycs85 May 26 '17 at 10:52
  • i tried using form_state but not able get values.e.g. ($form_state->getValues('body')) this prints blank array. I am new to drupal 8 can you please help me with small snipate of code? – Nikhil Valand May 29 '17 at 5:46

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.