function flickrfield_field in Flickr 6
File
- field/
flickrfield.module, line 158 - Defines a Flickr field type.
Code
function flickrfield_field($op, &$node, $field, &$items, $arg1, $arg2) {
switch ($op) {
case 'validate':
$form = $arg1;
if (!is_array($items)) {
return $items;
}
foreach ($items as $i => $item) {
if (empty($item['url'])) {
continue;
}
$info = flickr_get_info_by_url($item['url']);
if (!is_array($info)) {
form_set_error($field['field_name'], $info);
continue;
}
}
break;
case 'presave':
foreach ($items as $i => $item) {
$info = flickr_get_info_by_url($item['url']);
if (!is_array($info)) {
// Input was validated above. If we got here, it was simply an empty
// field.
continue;
}
$items[$i]['id'] = $info['id'];
if ($info['media'] == 'photo') {
$items[$i]['type'] = 'photo_id';
$items[$i]['nsid'] = $info['owner']['nsid'];
}
else {
$items[$i]['type'] = 'set_id';
$items[$i]['nsid'] = $info['owner'];
}
}
break;
}
}