You are here

function node_features_export_render in Features 6

Same name and namespace in other branches
  1. 7.2 includes/features.node.inc \node_features_export_render()
  2. 7 includes/features.node.inc \node_features_export_render()

Implementation of hook_features_export_render().

File

includes/features.node.inc, line 75

Code

function node_features_export_render($module, $data, $export = NULL) {
  $elements = array(
    'name' => TRUE,
    'module' => FALSE,
    'description' => TRUE,
    'has_title' => FALSE,
    'title_label' => TRUE,
    'has_body' => FALSE,
    'body_label' => TRUE,
    'min_word_count' => FALSE,
    'help' => TRUE,
  );
  $output = array();
  $output[] = '  $items = array(';
  foreach ($data as $type) {
    if ($info = node_get_types('type', $type)) {

      // Force module name to be 'features' if set to 'node. If we leave as
      // 'node' the content type will be assumed to be database-stored by
      // the node module.
      $info->module = $info->module === 'node' ? 'features' : $info->module;
      $output[] = "    '{$type}' => array(";
      foreach ($elements as $key => $t) {
        if ($t) {
          $text = str_replace("'", "\\'", $info->{$key});
          $text = !empty($text) ? "t('{$text}')" : "''";
          $output[] = "      '{$key}' => {$text},";
        }
        else {
          $output[] = "      '{$key}' => '{$info->{$key}}',";
        }
      }

      // Detect whether there are extra fields on this content type than have
      // been described in defaults. If so, add an additional key to the node
      // type info allowing it to be detected by Features as a component that can
      // be reverted (delete those extra fields) or updated (export those extra
      // fields to code).
      // Note that this key is only added if $export is not set - ie. we never
      // *actually* write this key to code.
      if (!isset($export) && module_exists('content') && module_exists($module)) {

        // If there are deleted fields, mark the content type as such
        $deleted_fields = array_diff(content_features_fields_normal($type), content_features_fields_default($type));
        if (!empty($deleted_fields)) {
          $output[] = "      'content_has_extra_fields' => TRUE,";
        }
      }
      $output[] = "    ),";
    }
  }
  $output[] = '  );';
  $output[] = '  return $items;';
  $output = implode("\n", $output);
  return array(
    'node_info' => $output,
  );
}