blockreference.feeds.inc in Block reference 7.2
File
blockreference.feeds.inc
View source
<?php
function blockreference_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_name) {
foreach (field_info_instances($entity_type, $bundle_name) as $name => $instance) {
$info = field_info_field($name);
if ($info['type'] == 'blockreference') {
$targets[$name . ':moddelta'] = array(
'name' => check_plain($instance['label']) . ' (moddelta)',
'callback' => 'blockreference_feeds_set_target',
'description' => t('The field instance @label of @field_name matched by moddelta.', array(
'@label' => $instance['label'],
'@field_name' => $name,
)),
'real_target' => $name,
);
}
}
}
function blockreference_feeds_set_target($source, $entity, $target, $value) {
$values = array_filter((array) $value);
if (!$value) {
return;
}
list($target, $match_key) = explode(':', $target, 2);
$language = isset($match_key['language']) ? $match_key['language'] : LANGUAGE_NONE;
$items = array();
foreach ($values as $value) {
@(list($module, $delta) = explode(':', $value));
if ($module && $delta) {
$exists = db_query('SELECT bid FROM {block} WHERE module = ? AND delta = ?', array(
$module,
$delta,
))
->fetchField();
if ($exists) {
$items[$language][]['moddelta'] = $value;
}
}
}
$entity->{$target} = $items;
}