feeds.feeds.inc 2.4 KB

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