You are here

function conditional_fields_features_export_render in Conditional Fields 7.3

Same name and namespace in other branches
  1. 6.2 includes/conditional_fields.features.inc \conditional_fields_features_export_render()

Implements hook_features_export_render().

File

includes/conditional_fields.features.inc, line 39
Features integration hooks.

Code

function conditional_fields_features_export_render($module_name, $data, $export = NULL) {
  $dependencies = conditional_fields_load_dependencies();
  if (empty($dependencies)) {
    return array();
  }
  $code = array();
  foreach ($data as $option) {
    $tokens = explode(':', $option);
    $entity = $tokens[0];
    $bundle = $tokens[1];
    if (isset($dependencies[$entity]) && isset($dependencies[$entity][$bundle])) {
      $info = $dependencies[$entity][$bundle];

      // Ensure that dependencies are always exported in the same order to
      // avoid fake overrides.
      ksort($info['dependents']);
      $code[] = '';
      $code[] = '  $items["' . $option . '"] = array(';
      foreach ($info['dependents'] as $dependent_field_name => $dependees) {
        foreach ($dependees as $dependee) {
          $code[] = "    array(";
          $code[] = "      'entity' => '" . $entity . "',";
          $code[] = "      'bundle' => '" . $bundle . "',";
          $code[] = "      'dependent' => '" . $dependent_field_name . "',";
          $code[] = "      'dependee' => '" . $dependee['dependee'] . "',";
          $code[] = "      'options' => " . features_var_export($dependee['options'], '      ') . ',';
          $code[] = '    ),';
        }
      }
      $code[] = '  );';
    }
  }
  if (empty($code)) {
    return array();
  }
  array_unshift($code, '  $items = array();');
  $code[] = '';
  $code[] = '  return $items;';
  $output = implode("\n", $code);
  return array(
    'conditional_fields_default_fields' => $output,
  );
}