Projet

Général

Profil

Paste
Télécharger (2,38 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / feeds / feeds.feeds.inc @ a192dc0b

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
  // Since a hook can be invoked multiple times during a request, reset the
28
  // "feeds_feeds_processor_targets" variable.
29
  // @see _feeds_feeds_processor_targets_alter()
30
  drupal_static_reset('feeds_feeds_processor_targets');
31
}
32

    
33
/**
34
 * Normalizes the target array.
35
 *
36
 * @param array &$targets
37
 *   The Feeds target array.
38
 */
39
function feeds_normalize_targets(array &$targets) {
40
  static $defaults = array(
41
    'description' => '',
42
    'summary_callbacks' => array(),
43
    'form_callbacks' => array(),
44
    'preprocess_callbacks' => array(),
45
    'unique_callbacks' => array(),
46
  );
47

    
48
  foreach (array_keys($targets) as $target) {
49
    $targets[$target] += $defaults;
50

    
51
    // Filter out any uncallable keys.
52
    _feeds_filter_callback_arrays($targets[$target]);
53
  }
54
}
55

    
56
/**
57
 * Filters the callbacks of a single target array.
58
 *
59
 * @param array &$target
60
 *   The target arary.
61
 */
62
function _feeds_filter_callback_arrays(array &$target) {
63
  // Migrate keys summary_callback and form_callback to the new keys.
64
  if (isset($target['summary_callback'])) {
65
    $target['summary_callbacks'][] = $target['summary_callback'];
66
  }
67
  if (isset($target['form_callback'])) {
68
    $target['form_callbacks'][] = $target['form_callback'];
69
  }
70
  unset($target['summary_callback'], $target['form_callback']);
71

    
72
  static $callback_keys = array(
73
    'summary_callbacks',
74
    'form_callbacks',
75
    'preprocess_callbacks',
76
    'unique_callbacks',
77
  );
78

    
79
  // Filter out any incorrect callbacks. Do it here so it only has to be done
80
  // once.
81
  foreach ($callback_keys as $callback_key) {
82
    $target[$callback_key] = array_filter($target[$callback_key], 'is_callable');
83
  }
84

    
85
  // This makes checking in FeedsProcessor::mapToTarget() simpler.
86
  if (empty($target['callback']) || !is_callable($target['callback'])) {
87
    unset($target['callback']);
88
  }
89
}