You are here

salesforce_api.features.inc in Salesforce Suite 7.2

Same filename and directory in other branches
  1. 6.2 salesforce_api/salesforce_api.features.inc

Salesforce features integration

File

salesforce_api/salesforce_api.features.inc
View source
<?php

// $Id$

/**
 * @file
 * Salesforce features integration
 */

/**
 * @defgroup {
 * Salesforce Fieldmap features integration functions
 */

/**
 * Implements hook_features_export_options().
 */
function salesforce_api_fieldmap_features_export_options() {
  $maps = salesforce_api_salesforce_fieldmap_load_all();
  $options = array();
  foreach ($maps as $machine_name => $map) {
    $options[$machine_name] = $map->drupal_entity . ' : ' . $map->drupal_bundle . ' => ' . $map->salesforce;
  }
  return $options;
}

/**
 * Implements hook_features_export().
 */
function salesforce_api_fieldmap_features_export($data, &$export, $module_name = 'salesforce_api') {

  // Export mappings from {salesforce_fieldmap}.
  return ctools_component_features_export('salesforce_fieldmap', $data, $export, $module_name);
}

/**
 * Implements hook_features_export_render().
 */
function salesforce_api_fieldmap_features_export_render($module, $data, $export = NULL) {
  return ctools_component_features_export_render('salesforce_fieldmap', 'salesforce_api', $data);
}

/**
 * Implements hook_features_revert().
 */
function salesforce_api_fieldmap_features_revert($module = 'salesforce_api') {
  ctools_component_features_revert($module);
}

/*
 * Implements hook_features_rebuild().
 */
function salesforce_fieldmap_features_rebuild($module) {
  $table = 'salesforce_fieldmap';
  $defaults = features_get_default($table, $module);
  if (empty($defaults)) {
    return;
  }

  // Revert.
  if (!empty($defaults)) {
    foreach ($defaults as $object) {
      if (empty($object->name) || empty($object->drupal_entity) || empty($object->salesforce)) {
        continue;
      }

      // If it exists, just update the record.
      $existing = salesforce_api_salesforce_fieldmap_load($object->name);
      $primary_key = empty($existing->in_code_only) ? 'name' : array();
      drupal_write_record('salesforce_fieldmap', $object, $primary_key);
    }
  }
}

/**
 * }
 */