Newer
Older
fago
committed
<?php
/**
* @file
* Rules integration.
*/
/**
* Implements hook_rules_event_info().
*/
function feeds_rules_event_info() {
$info = array();
$entity_info = entity_get_info();
Chris Leppanen
committed
fago
committed
foreach (feeds_importer_load_all() as $importer) {
$config = $importer->getConfig();
$processor = feeds_plugin($config['processor']['plugin_key'], $importer->id);
Chris Leppanen
committed
// It's possible to get FeedsMissingPlugin here which will break things
// since it doesn't implement FeedsProcessor::entityType().
if (!$processor instanceof FeedsProcessor) {
continue;
}
fago
committed
$entity_type = $processor->entityType();
$label = isset($entity_info[$entity_type]['label']) ? $entity_info[$entity_type]['label'] : $entity_type;
fago
committed
$info['feeds_import_'. $importer->id] = array(
'label' => t('Before saving an item imported via @name.', array('@name' => $importer->config['name'])),
'group' => t('Feeds'),
'variables' => array(
$entity_type => array(
'label' => t('Imported @label', array('@label' => $label)),
fago
committed
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
'type' => $entity_type,
// Saving is handled by feeds anyway (unless the skip action is used).
'skip save' => TRUE,
),
),
'access callback' => 'feeds_rules_access_callback',
);
// Add bundle information if the node processor is used.
if ($processor instanceof FeedsNodeProcessor) {
$config = $processor->getConfig();
$info['feeds_import_'. $importer->id]['variables'][$entity_type]['bundle'] = $config['content_type'];
}
}
return $info;
}
/**
* Implements of hook_rules_action_info().
*/
function feeds_rules_action_info() {
return array(
'feeds_skip_item' => array(
'base' => 'feeds_action_skip_item',
'label' => t('Skip import of feeds item'),
'group' => t('Feeds'),
'parameter' => array(
'entity' => array('type' => 'entity', 'label' => t('The feeds import item to be marked as skipped')),
),
'access callback' => 'feeds_rules_access_callback',
),
);
}
/**
* Mark feeds import item as skipped.
*/
function feeds_action_skip_item($entity_wrapper) {
$entity = $entity_wrapper->value();
if(isset($entity->feeds_item)) {
$entity->feeds_item->skip = TRUE;
}
}
/**
* Help callback for the skip action.
*/
function feeds_action_skip_item_help() {
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.");
}
/**
* Access callback for the feeds rules integration.
*/
function feeds_rules_access_callback() {
return user_access('administer feeds');
}