1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Feeds hooks.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Implements hook_feeds_processor_targets().
|
10
|
*/
|
11
|
function feeds_feeds_processor_targets($entity_type, $bundle) {
|
12
|
// Record that we've been called.
|
13
|
// @see _feeds_feeds_processor_targets_alter()
|
14
|
$called = &drupal_static('feeds_feeds_processor_targets', FALSE);
|
15
|
$called = TRUE;
|
16
|
|
17
|
return array();
|
18
|
}
|
19
|
|
20
|
/**
|
21
|
* Implements hook_feeds_processor_targets_alter().
|
22
|
*/
|
23
|
function feeds_feeds_processor_targets_alter(array &$targets, $entity_type, $bundle) {
|
24
|
// This hook gets called last, so that we normalize the whole array.
|
25
|
feeds_normalize_targets($targets);
|
26
|
}
|
27
|
|
28
|
/**
|
29
|
* Normalizes the target array.
|
30
|
*
|
31
|
* @param array &$targets
|
32
|
* The Feeds target array.
|
33
|
*/
|
34
|
function feeds_normalize_targets(array &$targets) {
|
35
|
static $defaults = array(
|
36
|
'description' => '',
|
37
|
'summary_callbacks' => array(),
|
38
|
'form_callbacks' => array(),
|
39
|
'preprocess_callbacks' => array(),
|
40
|
'unique_callbacks' => array(),
|
41
|
);
|
42
|
|
43
|
foreach (array_keys($targets) as $target) {
|
44
|
$targets[$target] += $defaults;
|
45
|
|
46
|
// Filter out any uncallable keys.
|
47
|
_feeds_filter_callback_arrays($targets[$target]);
|
48
|
}
|
49
|
}
|
50
|
|
51
|
/**
|
52
|
* Filters the callbacks of a single target array.
|
53
|
*
|
54
|
* @param array &$target
|
55
|
* The target arary.
|
56
|
*/
|
57
|
function _feeds_filter_callback_arrays(array &$target) {
|
58
|
// Migrate keys summary_callback and form_callback to the new keys.
|
59
|
if (isset($target['summary_callback'])) {
|
60
|
$target['summary_callbacks'][] = $target['summary_callback'];
|
61
|
}
|
62
|
if (isset($target['form_callback'])) {
|
63
|
$target['form_callbacks'][] = $target['form_callback'];
|
64
|
}
|
65
|
unset($target['summary_callback'], $target['form_callback']);
|
66
|
|
67
|
static $callback_keys = array(
|
68
|
'summary_callbacks',
|
69
|
'form_callbacks',
|
70
|
'preprocess_callbacks',
|
71
|
'unique_callbacks',
|
72
|
);
|
73
|
|
74
|
// Filter out any incorrect callbacks. Do it here so it only has to be done
|
75
|
// once.
|
76
|
foreach ($callback_keys as $callback_key) {
|
77
|
$target[$callback_key] = array_filter($target[$callback_key], 'is_callable');
|
78
|
}
|
79
|
|
80
|
// This makes checking in FeedsProcessor::mapToTarget() simpler.
|
81
|
if (empty($target['callback']) || !is_callable($target['callback'])) {
|
82
|
unset($target['callback']);
|
83
|
}
|
84
|
}
|