You are here

function sf_node_fieldmap_objects in Salesforce Suite 5.2

Same name and namespace in other branches
  1. 6.2 sf_node/sf_node.module \sf_node_fieldmap_objects()

Implementation of hook_fieldmap_objects_alter().

File

sf_node/sf_node.module, line 66
Integrates the core node object and various node related modules with the SalesForce API.

Code

function sf_node_fieldmap_objects($type) {
  $objects = array();

  // Define the data fields available for Drupal objects.
  if ($type == 'drupal') {

    // Add a definition for each node type.
    foreach (node_get_types() as $type) {

      // Define the node type object with the node ID field.
      $objects['node_' . $type->type] = array(
        'label' => t('@name node', array(
          '@name' => $type->name,
        )),
        'fields' => array(
          'nid' => array(
            'label' => t('Node ID'),
            'type' => SALESFORCE_FIELD_SOURCE_ONLY,
          ),
        ),
      );

      // Add a title field if the node type has one.
      if ($type->has_title) {
        $objects['node_' . $type->type]['fields']['title'] = array(
          'label' => check_plain($type->title_label),
          'type' => SALESFORCE_FIELD_REQUIRED,
        );
      }

      // Add a body field if the node type has one.
      if ($type->has_body) {
        $objects['node_' . $type->type]['fields']['body'] = array(
          'label' => check_plain($type->body_label),
        );
      }

      // Add the rest of the core fields.
      $objects['node_' . $type->type]['fields'] += array(
        'type' => array(
          'label' => t('Node type'),
        ),
        'status' => array(
          'label' => t('Is the node published?'),
        ),
        'promote' => array(
          'label' => t('Is the node promoted?'),
        ),
        'created' => array(
          'label' => t('Created timestamp'),
        ),
        'uid' => array(
          'label' => t("Author's user ID"),
        ),
        'name' => array(
          'label' => t("Author's name"),
        ),
      );
    }

    // Add CCK fields to the node object definitions.
    if (module_exists('content')) {

      // Loop through each of the content types.
      foreach (content_types() as $type) {

        // Add each of the fields to the node object definition.
        foreach ((array) $type['fields'] as $field) {

          // Choose a handler based on the type of the CCK field.
          switch ($field['type']) {

            // TODO: Decide if we want to make more specific handlers...
            // case 'text':
            // For example, I might set a handler for text fields that takes
            // the selected input format into account.
            default:
              $export_handler = '_sf_node_export_cck_default';
              $import_handler = '_sf_node_import_cck_default';
          }
          $objects['node_' . $type['type']]['fields'][$field['field_name']] = array(
            'label' => check_plain($field['widget']['label']),
            'group' => t('CCK fields'),
            'export' => $export_handler,
            'import' => $import_handler,
          );

          // If the field was a date field, add the "To" date if enabled.
          if ($field['type'] == 'date' && !empty($field['todate'])) {
            $objects['node_' . $type['type']]['fields'][$field['field_name'] . '_todate'] = array(
              'label' => t('@label (to date)', array(
                '@label' => $field['widget']['label'],
              )),
              'group' => t('CCK fields'),
              'export' => '_sf_node_export_cck_todate',
              'import' => '_sf_node_import_cck_todate',
            );
          }
        }
      }
    }
  }
  return $objects;
}