You are here

function lingotek_lingotek_entity_download_alter in Lingotek Translation 7.6

Same name and namespace in other branches
  1. 7.7 lingotek.module \lingotek_lingotek_entity_download_alter()

Implements hook_lingotek_entity_download_alter().

File

./lingotek.module, line 2760

Code

function lingotek_lingotek_entity_download_alter(&$params) {
  $entity = $params['entity'];
  $entity_type = $params['entity_type'];
  $xml = $params['xml'];
  $langcode = $params['langcode'];

  // Handle metatag translations
  if (module_exists('metatag') && variable_get('lingotek_translate_metatags') && metatag_entity_supports_metatags($entity_type) && !empty($xml->metatags)) {
    $metatags = array(
      $langcode => array(),
    );
    foreach ($xml->metatags as $tag => $content) {
      foreach ($content as $k => $v) {
        foreach ($v as $value => $element) {
          foreach ($element as $text) {
            $metatags[$langcode][$k] = array();
            $metatags[$langcode][$k]['value'] = lingotek_unfilter_placeholders(decode_entities($text));
          }
        }
      }

      // Remove the self-reference to the metatags tag.
      unset($content[0]);
    }
    list($id, $vid, $bundle) = lingotek_entity_extract_ids($entity_type, $entity);
    metatag_metatags_save($entity_type, $id, $vid, $metatags, $langcode);
  }
}