You are here

function sf_node_fieldmap_objects in Salesforce Suite 6.2

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

Implementation of hook_fieldmap_objects_alter().

File

sf_node/sf_node.module, line 166
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),
        );
      }

      // Add a body field if the node type has one.
      if ($type->has_body) {

        // Body is actually body+teaser
        $objects['node_' . $type->type]['fields']['body'] = array(
          'label' => check_plain($type->body_label),
          'export' => '_sf_node_export_body',
          'import' => '_sf_node_import_body',
        );
      }

      // 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'),
          'export' => '_sf_node_export_date',
          'import' => '_sf_node_import_date',
        ),
        'uid' => array(
          'label' => t("Author's user ID"),
          'type' => SALESFORCE_FIELD_SOURCE_ONLY,
        ),
        'name' => array(
          'label' => t("Author's username"),
          'type' => SALESFORCE_FIELD_SOURCE_ONLY,
        ),
        'mail' => array(
          'label' => t("Author's email"),
          'export' => '_sf_node_export_author_email',
          'type' => SALESFORCE_FIELD_SOURCE_ONLY,
        ),
        'blank' => array(
          'label' => t("(blank)"),
          'export' => '_sf_node_export_blank',
          'type' => SALESFORCE_FIELD_SOURCE_ONLY,
        ),
      );
    }

    // 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.
        $group = t('@type CCK fields', array(
          '@type' => $type['name'],
        ));
        $index = 'node_' . $type['type'];
        foreach ((array) $type['fields'] as $field) {

          // Choose a handler based on the type of the CCK field.
          $export_handler = $import_handler = FALSE;

          // @see sf_contrib.module
          if (function_exists('_sf_node_export_cck_' . $field['type'])) {
            $export_handler = '_sf_node_export_cck_' . $field['type'];
          }
          if (function_exists('_sf_node_import_cck_' . $field['type'])) {
            $import_handler = '_sf_node_import_cck_' . $field['type'];
          }
          if ($field['widget']['type'] == 'optionwidgets_onoff') {
            $export_handler = $export_handler ? $export_handler : '_sf_node_export_cck_checkbox';
          }
          else {
            $export_handler = $export_handler ? $export_handler : '_sf_node_export_cck_default';
          }
          $import_handler = $import_handler ? $import_handler : '_sf_node_import_cck_default';
          foreach ($field['columns'] as $column => $data) {
            $key = $field['field_name'];
            $my_label = check_plain($field['widget']['label']);
            if ($column != 'value') {
              $key .= ':' . $column;
              $my_label .= " ({$column})";
            }
            $my_group = t('@group: @label', array(
              '@group' => $group,
              '@label' => $field['widget']['label'],
            ));
            $objects[$index]['fields'][$key] = array(
              'group' => $my_group,
              'label' => $my_label,
              'export' => $export_handler,
              'import' => $import_handler,
              'type' => $field['type'],
              'multiple' => $field['multiple'],
            );
          }
        }
      }
    }
  }
  return $objects;
}