You are here

function uuid_term_features_export_render in UUID Features Integration 7

Same name and namespace in other branches
  1. 6 includes/uuid_term.features.inc \uuid_term_features_export_render()

Implements hook_features_export_render().

File

includes/uuid_term.features.inc, line 122
Features hooks for the uuid_term features component.

Code

function uuid_term_features_export_render($module, $data) {
  $translatables = $code = array();
  $code[] = '  $terms = array();';
  $code[] = '';
  foreach ($data as $uuid) {
    $terms = entity_uuid_load('taxonomy_term', array(
      $uuid,
    ), array(), TRUE);
    if (!count($terms)) {
      continue;
    }

    // Export the parent uuids.
    foreach ($terms as $term) {
      if ($parents = taxonomy_get_parents($term->tid)) {
        foreach ($parents as $parent) {
          $term->parent[] = $parent->uuid;
        }
      }
    }
    $first_term = reset($terms);

    // Clone entity to avoid changes by reference.
    $export = clone $first_term;

    // Do not export ids.
    unset($export->vid);
    unset($export->tid);

    // No need to export the rdf mapping.
    unset($export->rdf_mapping);
    $files = uuid_features_file_field_export($export, 'taxonomy_term');
    $entity_type = 'taxonomy_term';
    drupal_alter('uuid_entity_features_export_render', $entity_type, $export, $first_term, $module);
    $code[] = '  $terms[] = ' . features_var_export(get_object_vars($export), '  ') . ';';

    // Add packaged files, if any.
    if (!empty($files)) {
      foreach ($files as $filename => $src_path) {
        $return[$filename] = $src_path;
      }
    }
  }
  if (!empty($translatables)) {
    $code[] = features_translatables_export($translatables, '  ');
  }
  $code[] = '  return $terms;';
  $code = implode("\n", $code);
  $return['uuid_features_default_terms'] = $code;
  return $return;
}