[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/features/includes/ -> features.node.inc (source)

   1  <?php
   2  // $Id: features.node.inc,v 1.1.2.26 2010/07/24 21:37:51 yhahn Exp $
   3  
   4  /**
   5   * Implementation of hook_features_api().
   6   */
   7  function node_features_api() {
   8    return array(
   9      'node' => array(
  10        'name' => t('Content types'),
  11        'feature_source' => TRUE,
  12        'default_hook' => 'node_info',
  13      ),
  14    );
  15  }
  16  
  17  /**
  18   * Implementation of hook_features_export_options().
  19   */
  20  function node_features_export_options() {
  21    return node_get_types('names');
  22  }
  23  
  24  /**
  25   * Implementation of hook_features_export.
  26   */
  27  function node_features_export($data, &$export, $module_name = '') {
  28    $pipe = array();
  29    $map = features_get_default_map('node');
  30  
  31    foreach ($data as $type) {
  32      // Poll node module to determine who provides the node type.
  33      if ($info = node_get_types('module', $type)) {
  34        $export['dependencies'][$info] = $info;
  35  
  36        // If this node type is provided by a different module, add it as a dependency
  37        if (isset($map[$type]) && $map[$type] != $module_name) {
  38          $export['dependencies'][$map[$type]] = $map[$type];
  39        }
  40        // Otherwise export the node type.
  41        elseif (in_array($info, array('node', 'features'))) {
  42          $export['features']['node'][$type] = $type;
  43        }
  44  
  45        // Create a pipe for CCK fields
  46        if (module_exists('content')) {
  47          $content_info = content_types($type);
  48          if (!empty($content_info['fields'])) {
  49            foreach ($content_info['fields'] as $key => $field) {
  50              $pipe['content'][] = "{$type}-{$field['field_name']}";
  51            }
  52            // If strongarm is present, create a pipe for the extra field weights
  53            // variable to be exported.
  54            if (module_exists('strongarm')) {
  55              $pipe['variable'][] = "content_extra_weights_{$type}";
  56            }
  57          }
  58          // Create a pipe for Fieldgroups
  59          if (function_exists('fieldgroup_groups') && $groups = fieldgroup_groups($type)) {
  60            foreach ($groups as $group) {
  61              $pipe['fieldgroup'][] = "{$type}-{$group['group_name']}";
  62            }
  63          }
  64        }
  65      }
  66    }
  67  
  68    return $pipe;
  69  }
  70  
  71  /**
  72   * Implementation of hook_features_export_render().
  73   */
  74  function node_features_export_render($module, $data, $export = NULL) {
  75    $elements = array(
  76      'name' => TRUE,
  77      'module' => FALSE,
  78      'description' => TRUE,
  79      'has_title' => FALSE,
  80      'title_label' => TRUE,
  81      'has_body' => FALSE,
  82      'body_label' => TRUE,
  83      'min_word_count' => FALSE,
  84      'help' => TRUE,
  85    );
  86    $output = array();
  87    $output[] = '  $items = array(';
  88    foreach ($data as $type) {
  89      if ($info = node_get_types('type', $type)) {
  90        // Force module name to be 'features' if set to 'node. If we leave as
  91        // 'node' the content type will be assumed to be database-stored by
  92        // the node module.
  93        $info->module = ($info->module === 'node') ? 'features' : $info->module;
  94        $output[] = "    '{$type}' => array(";
  95        foreach ($elements as $key => $t) {
  96          if ($t) {
  97            $text = str_replace("'", "\'", $info->$key);
  98            $text = !empty($text) ? "t('{$text}')" : "''";
  99            $output[] = "      '{$key}' => {$text},";
 100          }
 101          else {
 102            $output[] = "      '{$key}' => '{$info->$key}',";
 103          }
 104        }
 105        // Detect whether there are extra fields on this content type than have
 106        // been described in defaults. If so, add an additional key to the node
 107        // type info allowing it to be detected by Features as a component that can
 108        // be reverted (delete those extra fields) or updated (export those extra
 109        // fields to code).
 110        // Note that this key is only added if $export is not set - ie. we never
 111        // *actually* write this key to code.
 112        if (!isset($export) && module_exists('content') && module_exists($module)) {
 113          // If there are deleted fields, mark the content type as such
 114          $deleted_fields = array_diff(content_features_fields_normal($type), content_features_fields_default($type));
 115          if (!empty($deleted_fields)) {
 116            $output[] = "      'content_has_extra_fields' => TRUE,";
 117          }
 118        }
 119        $output[] = "    ),";
 120      }
 121    }
 122    $output[] = '  );';
 123    $output[] = '  return $items;';
 124    $output = implode("\n", $output);
 125    return array('node_info' => $output);
 126  }
 127  
 128  /**
 129   * Implementation of hook_features_revert().
 130   *
 131   * @param $module
 132   * name of module to revert content for
 133   */
 134  function node_features_revert($module = NULL) {
 135    if ($default_types = features_get_default('node', $module)) {
 136      foreach ($default_types as $type_name => $type_info) {
 137        // We need to de-activate any missing fields. De-activating allows us to
 138        // preserve data. We de-activate by setting the widget_active flag to 0;
 139        // widget_active is incorrectly named, and really should be
 140        // instance_active
 141        if (module_exists('content')) {
 142          // Our existing fields ($fields) needs to be the first argument here,
 143          // so only fields that don't exist in code can be de-activated.
 144          if ($deleted_fields = array_diff(content_features_fields_normal($type_name), content_features_fields_default($type_name))) {
 145            foreach($deleted_fields as $field_name) {
 146              db_query("UPDATE {". content_instance_tablename() ."} SET widget_active = 0 WHERE field_name = '%s' AND type_name = '%s'", $field_name, $type_name);
 147            }
 148          }
 149        }
 150        // Delete node types
 151        // We don't use node_type_delete() because we do not actually
 152        // want to delete the node type (and invoke hook_node_type()).
 153        // This can lead to bad consequences like CCK deleting field
 154        // storage in the DB.
 155        db_query("DELETE FROM {node_type} WHERE type = '%s'", $type_name);
 156      }
 157      node_types_rebuild();
 158      menu_rebuild();
 159    }
 160  }


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7