feeds.rules.inc 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * @file
  4. * Rules integration.
  5. */
  6. /**
  7. * Implements hook_rules_event_info().
  8. */
  9. function feeds_rules_event_info() {
  10. $info = array();
  11. $entity_info = entity_get_info();
  12. foreach (feeds_importer_load_all() as $importer) {
  13. $config = $importer->getConfig();
  14. $processor = feeds_plugin($config['processor']['plugin_key'], $importer->id);
  15. // It's possible to get FeedsMissingPlugin here which will break things
  16. // since it doesn't implement FeedsProcessor::entityType().
  17. if (!$processor instanceof FeedsProcessor) {
  18. continue;
  19. }
  20. $entity_type = $processor->entityType();
  21. $label = isset($entity_info[$entity_type]['label']) ? $entity_info[$entity_type]['label'] : $entity_type;
  22. $info['feeds_import_'. $importer->id] = array(
  23. 'label' => t('Before saving an item imported via @name.', array('@name' => $importer->config['name'])),
  24. 'group' => t('Feeds'),
  25. 'variables' => array(
  26. $entity_type => array(
  27. 'label' => t('Imported @label', array('@label' => $label)),
  28. 'type' => $entity_type,
  29. // Saving is handled by feeds anyway (unless the skip action is used).
  30. 'skip save' => TRUE,
  31. ),
  32. ),
  33. 'access callback' => 'feeds_rules_access_callback',
  34. );
  35. // Add bundle information if the node processor is used.
  36. if ($processor instanceof FeedsNodeProcessor) {
  37. $config = $processor->getConfig();
  38. $info['feeds_import_'. $importer->id]['variables'][$entity_type]['bundle'] = $config['content_type'];
  39. }
  40. }
  41. return $info;
  42. }
  43. /**
  44. * Implements of hook_rules_action_info().
  45. */
  46. function feeds_rules_action_info() {
  47. return array(
  48. 'feeds_skip_item' => array(
  49. 'base' => 'feeds_action_skip_item',
  50. 'label' => t('Skip import of feeds item'),
  51. 'group' => t('Feeds'),
  52. 'parameter' => array(
  53. 'entity' => array('type' => 'entity', 'label' => t('The feeds import item to be marked as skipped')),
  54. ),
  55. 'access callback' => 'feeds_rules_access_callback',
  56. ),
  57. );
  58. }
  59. /**
  60. * Mark feeds import item as skipped.
  61. */
  62. function feeds_action_skip_item($entity_wrapper) {
  63. $entity = $entity_wrapper->value();
  64. if (isset($entity->feeds_item)) {
  65. $entity->feeds_item->skip = TRUE;
  66. }
  67. }
  68. /**
  69. * Help callback for the skip action.
  70. */
  71. function feeds_action_skip_item_help() {
  72. return t("This action allows skipping certain feed items during feeds processing, i.e. before an imported item is saved. Once this action is used on a item, the changes to the entity of the feed item are not saved.");
  73. }
  74. /**
  75. * Access callback for the feeds rules integration.
  76. */
  77. function feeds_rules_access_callback() {
  78. return user_access('administer feeds');
  79. }