Last active
April 14, 2016 09:30
-
-
Save HelenaEksler/bf8c207c4abe5c11a6d4 to your computer and use it in GitHub Desktop.
Function to add translation object to the migrated entity.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function addLanguagesToEntityTranslations($entity_type, $entity) { | |
// Get the basic information about the entity. | |
$entity_info = entity_get_info($entity_type); | |
// Get the existing site languages. | |
$languages = array_keys(language_list()); | |
// Add to the entity translation object. Set the original language to | |
// the entity's default language. | |
$entity->translations = (object) array( | |
'original' => $entity->language, | |
); | |
$data = array(); | |
foreach($languages as $language) { | |
// For each language set the data array. | |
$data[$language] = array( | |
'entity_type' => $entity_type, | |
'entity_id' => $entity->{$entity_info['entity keys']['id']}, | |
'language' => $language, | |
'source' => $language == $entity->language ? '' : $entity->language, | |
'uid' => '0', | |
'status' => '1', | |
'translate' => '0', | |
); | |
} | |
// Add the data array to the entity translation object. | |
$entity->translations->data = $data; | |
// Update the entity. | |
entity_save($entity_type, $entity); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment