function lingotek_entity_xml_body in Lingotek Translation 7.6
Same name and namespace in other branches
- 7.7 lingotek.util.inc \lingotek_entity_xml_body()
- 7.5 lingotek.util.inc \lingotek_entity_xml_body()
Return the xml representation of the source content for an entity.
Parameters
$entity_type: A string containing a Drupal entity type.
object $entity: A Drupal entity.
Return value
string The XML representation of the entity in Lingotek format.
2 calls to lingotek_entity_xml_body()
- LingotekEntity::documentLingotekXML in lib/
Drupal/ lingotek/ LingotekEntity.php - Gets the contents of this item formatted as XML that can be sent to Lingotek.
- lingotek_entity_changed in ./
lingotek.util.inc
File
- ./
lingotek.util.inc, line 295 - Utility functions.
Code
function lingotek_entity_xml_body($entity_type, $entity) {
$translatable = array();
$translate = variable_get('lingotek_enabled_fields', array());
list($id, $vid, $bundle) = lingotek_entity_extract_ids($entity_type, $entity);
$fields_desired = isset($translate[$entity_type][$bundle]) ? $translate[$entity_type][$bundle] : array();
if (empty($fields_desired) && lingotek_oneoff_translate($entity)) {
$fields_desired = lingotek_get_translatable_fields_by_content_type($entity_type, $bundle);
}
foreach ($fields_desired as $value) {
$field = field_info_field($value);
if (isset($field)) {
array_push($translatable, $value);
}
}
$content = lingotek_xml_fields($entity, $translatable, $entity->language);
/* deprecated with config translation
//Menus related to the page:
// Do we still want this? Config translation translates these items
$menu = menu_link_get_preferred('node/' . $entity->nid);
$txt = $menu['link_title'];
if ($txt != "") {
$content = $content . "<menu_title><![CDATA[$txt]]></menu_title>\n";
} */
if ($entity_type == 'node') {
//URL Alias related to the page:
$url_alias_translation = isset($entity->lingotek['url_alias_translation']) ? $entity->lingotek['url_alias_translation'] : 0;
if ($url_alias_translation == 1) {
$conditions = array(
'source' => 'node/' . $entity->nid,
);
if ($entity->language != LANGUAGE_NONE) {
$conditions['language'] = $entity->language;
}
$path = path_load($conditions);
if ($path !== FALSE) {
$url = $path['alias'];
$content = $content . "<url_alias><![CDATA[{$url}]]></url_alias>\n";
}
}
}
$labeled_content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><contents>{$content}</contents>";
try {
$xml = new LingotekXMLElement($labeled_content);
$hook_params = array(
'entity_type' => $entity_type,
'entity' => $entity,
'xml' => $xml,
'langcode' => $entity->language,
);
// Allow other modules to manipulate the uploaded content.
drupal_alter('lingotek_entity_upload', $hook_params);
// Return to string form, after any modifications.
$labeled_content = $xml
->asXML();
} catch (Exception $e) {
LingotekLog::error("Failed to parse or modify XML before uploading. Error: @error. Text: !xml.", array(
'!xml' => $text,
'@error' => $e
->getMessage(),
));
}
return $labeled_content;
}