function sf_entity_fieldmap_objects in Salesforce Suite 7
Same name and namespace in other branches
- 7.2 sf_entity/sf_entity.module \sf_entity_fieldmap_objects()
Implements hook_fieldmap_objects_alter().
File
- sf_entity/
sf_entity.module, line 225 - Integrates fieldable entities with the Salesforce API.
Code
function sf_entity_fieldmap_objects($type) {
$objects = array();
// Define the data fields available for Drupal objects.
if ($type == 'drupal') {
$entities = field_info_bundles();
$fields = field_info_fields();
// For each entity-bundle-field-column combo, assign a field definition.
foreach ($entities as $entity => $bundles) {
$entity_info = entity_get_info($entity);
if (!$entity_info['fieldable']) {
continue;
}
$objects[$entity] = array();
foreach ($bundles as $bundle_name => $bundle_info) {
$objects[$entity][$bundle_name] = array(
'label' => $entity_info['label'] . ': ' . $bundle_info['label'],
'fields' => array(),
);
// Add entity keys (id, revision, & bundle).
foreach ($entity_info['entity keys'] as $key => $value) {
if (empty($value)) {
continue;
}
$objects[$entity][$bundle_name]['fields'][$value] = array(
'label' => $value,
'group' => 'IDs',
);
}
// For each Field API field column, add a definition
$fields = field_info_instances($entity, $bundle_name);
foreach ($fields as $field_name => $field_info) {
$more_field_info = field_info_field($field_name);
foreach ($more_field_info['columns'] as $col_name => $col_data) {
// There's probably no reason to clutter the admin UI with the
// "format" value for this field.
if ($col_name == 'format') {
continue;
}
$data = array(
'label' => t('@label (@column)', array(
'@label' => $field_info['label'],
'@column' => $col_name,
)),
'group' => 'Fields',
'export' => 'sf_entity_export_field_default',
'import' => 'sf_entity_import_field_default',
);
$key = $field_name . ':' . $col_name;
$objects[$entity][$bundle_name]['fields'][$key] = $data;
}
}
// Add core fields which are outside of Field API
switch ($entity) {
case 'node':
$node_type = node_type_load($bundle_name);
if ($node_type->has_title) {
$objects['node'][$bundle_name]['fields']['title'] = array(
'label' => $node_type->title_label,
'group' => 'Node Fields',
);
}
break;
case 'user':
$objects['user'][$bundle_name]['fields']['pass'] = array(
'label' => 'Password',
'group' => 'User Fields',
);
$objects['user'][$bundle_name]['fields']['name'] = array(
'label' => 'Username',
'group' => 'User Fields',
);
$objects['user'][$bundle_name]['fields']['mail'] = array(
'label' => 'Email',
'group' => 'User Fields',
);
break;
}
}
}
}
return $objects;
}