You are here

function uuid_term_features_export_render in UUID Features Integration 6

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

Implementation of hook_features_export_render().

File

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

Code

function uuid_term_features_export_render($module = 'foo', $data) {
  $translatables = $code = array();
  $code[] = '  $terms = array();';
  $code[] = '';
  foreach ($data as $uuid) {
    $tid = db_result(db_query('SELECT tid FROM {uuid_term_data} WHERE uuid = "%s"', $uuid));
    $term = taxonomy_get_term($tid);
    if (!$term) {
      continue;
    }
    $export = array(
      'uuid' => $uuid,
    );

    // Whitelist of term properties.
    $props = array(
      'name',
      'description',
      'weight',
    );
    foreach ($props as $key) {
      if (isset($term->{$key})) {
        $export[$key] = $term->{$key};
      }
    }

    // Get the UUID of the term's parent terms.
    $parents = taxonomy_get_parents($tid);
    foreach ($parents as $parent) {
      $export['parent'][] = uuid_get_uuid('term_data', 'tid', $parent->tid);
    }

    // Get the UUID of the term's vocabulary.
    $query = 'SELECT uv.uuid FROM {uuid_vocabulary} uv WHERE uv.vid = "%s"';
    $voc_uuid = db_result(db_query($query, $term->vid));
    $export['uuid_vocabulary'] = $voc_uuid;
    $code[] = '  $terms[] = ' . features_var_export($export, '  ') . ';';
  }
  if (!empty($translatables)) {
    $code[] = features_translatables_export($translatables, '  ');
  }
  $code[] = '  return $terms;';
  $code = implode("\n", $code);
  return array(
    'uuid_features_default_terms' => $code,
  );
}