You are here

function feeds_rules_event_info in Feeds 8.2

Same name and namespace in other branches
  1. 7.2 feeds.rules.inc \feeds_rules_event_info()

Implements hook_rules_event_info().

File

./feeds.rules.inc, line 11
Rules integration.

Code

function feeds_rules_event_info() {

  // General events definitions.
  $info = array(
    'feeds_before_import' => array(
      'label' => t('Before importing feed'),
      'group' => t('Feeds'),
      'variables' => array(
        'source' => array(
          'type' => 'feeds_source',
          'label' => 'Feeds source',
        ),
      ),
    ),
    'feeds_after_import' => array(
      'label' => t('After importing feed'),
      'group' => t('Feeds'),
      'variables' => array(
        'source' => array(
          'type' => 'feeds_source',
          'label' => 'Feeds source',
        ),
      ),
    ),
  );

  // Per importer events definitions.
  $entity_info = entity_get_info();
  foreach (feeds_importer_load_all() as $importer) {
    $config = $importer
      ->getConfig();
    $processor = feeds_plugin($config['processor']['plugin_key'], $importer->id);

    // It's possible to get FeedsMissingPlugin here which will break things
    // since it doesn't implement FeedsProcessor::entityType().
    if (!$processor instanceof FeedsProcessor) {
      continue;
    }
    $entity_type = $processor
      ->entityType();
    $label = isset($entity_info[$entity_type]['label']) ? $entity_info[$entity_type]['label'] : $entity_type;
    $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,
          )),
          '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) {
      $info['feeds_import_' . $importer->id]['variables'][$entity_type]['bundle'] = $processor
        ->bundle();
    }
  }
  return $info;
}