You are here

function uuid_file_entity_features_export_render in UUID Features Integration 7

Implements hook_features_export_render().

File

includes/uuid_file_entity.features.inc, line 71
Features hooks for the uuid_file_entity features component.

Code

function uuid_file_entity_features_export_render($module, $data) {
  $translatables = $code = array();
  $export_mode = variable_get('uuid_features_file_mode', 'inline');
  switch ($export_mode) {
    case 'local':
      $export_var = 'uuid_features_file_path';
      break;
    case 'remote':
      $export_var = 'uuid_features_file_url';
      break;
    case 'packaged':
      $export_var = 'uuid_features_packaged_file_path';
      break;
    default:
    case 'inline':
      $export_var = 'uuid_features_file_data';
      break;
  }
  $code[] = '  $files = array();';
  $code[] = '';
  $fids = entity_get_id_by_uuid('file', $data);

  // Always sort by the uuid to ensure the order is maintained.
  ksort($fids);
  foreach ($fids as $uuid => $fid) {

    // Only export the file if it exists.
    if ($fid === FALSE) {
      continue;
    }

    // Attempt to load the file, using a fresh cache.
    $file = file_load($fid, NULL, TRUE);
    if (empty($file)) {
      continue;
    }
    if (!empty($file->path)) {
      $file->pathauto_perform_alias = FALSE;
    }

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

    // Don't cause conflicts with fid/vid/revision_timestamp/changed fields.
    $export->{$export_var} = uuid_features_file_export($export, $export_mode);
    $entity_type = 'file';
    drupal_alter('uuid_entity_features_export_render', $entity_type, $export, $file, $module);
    drupal_alter('uuid_file_entity_features_export_render', $export, $file, $module);
    unset($export->fid, $export->timestamp, $export->created);
    $code[] = '  $files[] = ' . features_var_export($export, '  ') . ';';
  }
  if (!empty($translatables)) {
    $code[] = features_translatables_export($translatables, '  ');
  }
  $code[] = '  return $files;';
  $code = implode("\n", $code);
  return array(
    'uuid_features_default_file_entities' => $code,
  );
}