As an example for the API, take a look at mappers/content.inc should be used. For documenting the Mapping API, I opened an issue #623466: Document mapping API.
Yes also for me #6 is working ok. I import some CSV data with affiliate link and used this patch to map it to CCK link field.
You can see example here: http://www.pine-chest-of-drawers.com/
- Did some minor cleanup
- Tests throw 2 exceptions in the same place (getFormFieldsValues())
- getFormFieldsNames() and getFormFieldsValues() are missing comments
- I am not 100 % sure what the extended logic in link_feeds_set_target() is doing - mongolito404, could you comment that?
- Changed delimiters from # to : as this is the route we started taking with taxonomy mapper.
I tested the patch from #11 with a CSV import feed with 3 different URL sources/targets. All of them worked for me. Just wanted to provide some feedback.
In link_feeds_set_target()
- $defaults is used to store the default title and attributes for the field
- Entries in $defaults are indexed by node type and field name ($defaults[$node->type][$field_name])
- For each value, the defaults are assigned to the field if not already set
- Each URL value is cleaned and validated by (($v = link_cleanup_url($v)) && valid_url($v, true))
- Title values are not validated and directly assigned to the field
#1
Port the *link mapper of course.
#2
As an example for the API, take a look at mappers/content.inc should be used. For documenting the Mapping API, I opened an issue #623466: Document mapping API.
#3
I need this for my project so I started working on it.
I need to write some tests and create a patch file but here what i have at the moment
<?php
function link_feeds_node_processor_targets_alter($targets, $content_type) {
$info = content_types($content_type);
$fields = array();
if (isset($info['fields']) && count($info['fields'])) {
foreach ($info['fields'] as $field_name => $field) {
if ($field['type'] == array('link')) {
$name = isset($field['widget']['label']) ? $field['widget']['label'] : $field_name;
$targets[$field_name.'#url'] = array(
'name' => $name . ' (' . t('url').')',
'callback' => 'link_feeds_set_target',
'description' => t('The URL for the CCK !name field of the node.', array('!name' => $name)),
);
if(in_array($field['title'], array('optional', 'required'))) {
$targets[$field_name.'#title'] = array(
'name' => $name . ' (' . t('title').')',
'callback' => 'link_feeds_set_target',
'description' => t('The title for the CCK !name field of the node.', array('!name' => $name)),
);
}
}
}
}
}
function link_feeds_set_target($node, $target, $value) {
static $defaults = array();
list($field_name, $sub_field) = split('#', $target);
if(!isset($defaults[$node->type][$field_name])) {
$field = content_fields($field_name, $node->type);
$defaults[$node->type][$field_name]['attributes'] = $field['attributes'];
if(!in_array($field['title'], array('optional', 'required', 'none'))) {
$defaults[$node->type][$field_name]['title'] = $field['title'];
}
}
$field_data = isset($node->$field_name) ? $node->$field_name : array();
if(!is_array($value)) {
$value = array($value);
}
$i = 0;
foreach ($value as $v) {
if(!isset($field_data[$i])) {
$field_data[$i] = $defaults[$node->type][$field_name];
}
if ($sub_field != 'url' || (($v = link_cleanup_url($v)) && valid_url($v, true))) {
$field_data[$i][$sub_field] = $v;
}
$i++;
}
$node->$field_name = $field_data;
}
?>
I don't know if using hash in the targets for subfields is the right way of doing it but it works.
#4
Here is a patch file against HEAD with the mapper in #3 and its test case.
#5
Contains tabs as indents...
#6
Sorry for the tabs, here is a fixed patch.
#7
The patch in #6 worked beautifully for me.
#8
Yes also for me #6 is working ok. I import some CSV data with affiliate link and used this patch to map it to CCK link field.
You can see example here:
http://www.pine-chest-of-drawers.com/
#9
I just want to confirm that this patch worked flawlessly for me to!
#10
Working for me too.
#11
- Did some minor cleanup
- Tests throw 2 exceptions in the same place (getFormFieldsValues())
- getFormFieldsNames() and getFormFieldsValues() are missing comments
- I am not 100 % sure what the extended logic in link_feeds_set_target() is doing - mongolito404, could you comment that?
- Changed delimiters from # to : as this is the route we started taking with taxonomy mapper.
#12
I tested the patch from #11 with a CSV import feed with 3 different URL sources/targets. All of them worked for me. Just wanted to provide some feedback.
#13
Subscribing, greetings, Martijn
#14
In link_feeds_set_target()
- $defaults is used to store the default title and attributes for the field
- Entries in $defaults are indexed by node type and field name (
$defaults[$node->type][$field_name])- For each value, the defaults are assigned to the field if not already set
- Each URL value is cleaned and validated by
(($v = link_cleanup_url($v)) && valid_url($v, true))- Title values are not validated and directly assigned to the field