public function FeedsDataProcessor::getMappingTargets in Feeds 6
Return available mapping targets.
Overrides FeedsProcessor::getMappingTargets
File
- plugins/
FeedsDataProcessor.inc, line 113 - Definition of FeedsDataProcessor.
Class
- FeedsDataProcessor
- Creates simple table records from feed items. Uses Data module.
Code
public function getMappingTargets() {
$schema = $this
->table()
->get('table_schema');
$meta = $this
->table()
->get('meta');
// Collect all existing fields except id and field_nid and offer them as
// mapping targets.
$existing_fields = $new_fields = array();
if (isset($schema['fields'])) {
foreach ($schema['fields'] as $field_name => $field) {
if (!in_array($field_name, array(
'id',
'feed_nid',
))) {
// Any existing field can be optionally unique.
// @todo Push this reverse mapping of spec to short name into data
// module.
$type = $field['type'];
if ($type == 'int' && $field['unsigned']) {
$type = 'unsigned int';
}
$existing_fields[$field_name] = array(
'name' => empty($meta['fields'][$field_name]['label']) ? $field_name : $meta['fields'][$field_name]['label'],
'description' => t('Field of type !type.', array(
'!type' => $type,
)),
'optional_unique' => TRUE,
);
}
}
}
// Do the same for every joined table.
foreach ($this
->handler()->joined_tables as $table) {
$schema = data_get_table($table)
->get('table_schema');
if (isset($schema['fields'])) {
foreach ($schema['fields'] as $field_name => $field) {
if (!in_array($field_name, array(
'id',
'feed_nid',
))) {
// Fields in joined tables can't be unique.
$type = $field['type'];
if ($type == 'int' && $field['unsigned']) {
$type = 'unsigned int';
}
$existing_fields["{$table}.{$field_name}"] = array(
'name' => $table . '.' . (empty($meta['fields'][$field_name]['label']) ? $field_name : $meta['fields'][$field_name]['label']),
'description' => t('Joined field of type !type.', array(
'!type' => $type,
)),
'optional_unique' => FALSE,
);
}
}
}
}
// Now add data field types as mapping targets.
$field_types = drupal_map_assoc(array_keys(data_get_field_definitions()));
foreach ($field_types as $k => $v) {
$new_fields['new:' . $k] = array(
'name' => t('[new] !type', array(
'!type' => $v,
)),
'description' => t('Creates a new column of type !type.', array(
'!type' => $v,
)),
);
}
$fields = $new_fields + $existing_fields;
drupal_alter('feeds_data_processor_targets', $fields, $this
->table()
->get('name'));
return $fields;
}