6 * @verbinclude README.txt
10 * Feeds offers a CTools based plugin API. Fetchers, parsers and processors are
11 * declared to Feeds as plugins.
13 * @see feeds_feeds_plugins()
18 * @defgroup pluginapi Plugin API
23 * Example of a CTools plugin hook that needs to be implemented to make
24 * hook_feeds_plugins() discoverable by CTools and Feeds. The hook specifies
25 * that the hook_feeds_plugins() returns Feeds Plugin API version 1 style
28 function hook_ctools_plugin_api($owner, $api) {
29 if ($owner == 'feeds' && $api == 'plugins') {
30 return array('version' => 1);
35 * A hook_feeds_plugins() declares available Fetcher, Parser or Processor
36 * plugins to Feeds. For an example look at feeds_feeds_plugin(). For exposing
37 * this hook hook_ctools_plugin_api() MUST be implemented, too.
39 * @see feeds_feeds_plugin()
41 function hook_feeds_plugins() {
43 $info['MyFetcher'] = array(
44 'name' => 'My Fetcher',
45 'description' => 'Fetches my stuff.',
46 'help' => 'More verbose description here. Will be displayed on fetcher selection menu.',
48 'parent' => 'FeedsFetcher',
49 'class' => 'MyFetcher',
50 'file' => 'MyFetcher.inc',
51 'path' => drupal_get_path('module', 'my_module'), // Feeds will look for MyFetcher.inc in the my_module directory.
54 $info['MyParser'] = array(
55 'name' => 'ODK parser',
56 'description' => 'Parse my stuff.',
57 'help' => 'More verbose description here. Will be displayed on parser selection menu.',
59 'parent' => 'FeedsParser', // Being directly or indirectly an extension of FeedsParser makes a plugin a parser plugin.
60 'class' => 'MyParser',
61 'file' => 'MyParser.inc',
62 'path' => drupal_get_path('module', 'my_module'),
65 $info['MyProcessor'] = array(
66 'name' => 'ODK parser',
67 'description' => 'Process my stuff.',
68 'help' => 'More verbose description here. Will be displayed on processor selection menu.',
70 'parent' => 'FeedsProcessor',
71 'class' => 'MyProcessor',
72 'file' => 'MyProcessor.inc',
73 'path' => drupal_get_path('module', 'my_module'),
84 * @defgroup import Import and clear hooks
89 * Invoked after a feed source has been parsed, before it will be processed.
92 * FeedsImporter object that has been used for importing the feed.
94 * FeedsSource object that describes the source that has been imported.
96 function hook_feeds_after_parse(FeedsImporter
$importer, FeedsSource
$source) {
97 // For example, set title of imported content:
98 $source->batch
->setTitle('Import number '.
my_module_import_id());
102 * Invoked after a feed source has been imported.
105 * FeedsImporter object that has been used for importing the feed.
107 * FeedsSource object that describes the source that has been imported.
109 function hook_feeds_after_import(FeedsImporter
$importer, FeedsSource
$source) {
110 // See geotaxonomy module's implementation for an example.
114 * Invoked after a feed source has been cleared of its items.
117 * FeedsImporter object that has been used for clearing the feed.
119 * FeedsSource object that describes the source that has been cleared.
121 function hook_feeds_after_clear(FeedsImporter
$importer, FeedsSource
$source) {
129 * @defgroup mappingapi Mapping API
134 * Alter mapping sources.
136 * Use this hook to add additional mapping sources for any parser. Allows for
137 * registering a callback to be invoked at mapping time.
139 * my_callback(FeedsImportBatch $batch, $key)
141 * @see my_source_get_source().
142 * @see locale_feeds_parser_sources_alter().
144 function hook_feeds_parser_sources_alter(&$sources, $content_type) {
145 $sources['my_source'] = array(
146 'name' => t('Images in description element'),
147 'description' => t('Images occuring in the description element of a feed item.'),
148 'callback' => 'my_source_get_source',
153 * Example callback specified in hook_feeds_parser_sources_alter().
155 * To be invoked on mapping time.
158 * The FeedsImportBatch object being mapped from.
160 * The key specified in the $sources array in
161 * hook_feeds_parser_sources_alter().
164 * The value to be extracted from the source.
166 * @see hook_feeds_parser_sources_alter().
167 * @see locale_feeds_get_source().
169 function my_source_get_source(FeedsImportBatch
$batch, $key) {
170 $item = $batch->currentItem();
171 return my_source_parse_images($item['description']);
175 * Alter mapping targets for entities. Use this hook to add additional target
176 * options to the mapping form of Node processors.
178 * If the key in $targets[] does not correspond to the actual key on the node
179 * object ($node->key), real_target MUST be specified. See mappers/link.inc
181 * For an example implementation, see mappers/content.inc
184 * Array containing the targets to be offered to the user. Add to this array
185 * to expose additional options. Remove from this array to suppress options.
186 * Remove with caution.
187 * @param $entity_type
188 * The entity type of the target, for instance a 'node' entity.
189 * @param $content_type
190 * The content type of the target node.
192 function hook_feeds_processor_targets_alter(&$targets, $entity_type, $content_type) {
193 if ($entity_type == 'node') {
194 $targets['my_node_field'] = array(
195 'name' => t('My custom node field'),
196 'description' => t('Description of what my custom node field does.'),
197 'callback' => 'my_module_set_target',
199 $targets['my_node_field2'] = array(
200 'name' => t('My Second custom node field'),
201 'description' => t('Description of what my second custom node field does.'),
202 'callback' => 'my_module_set_target2',
203 'real_target' => 'my_node_field_two', // Specify real target field on node.
209 * Example callback specified in hook_feeds_processor_targets_alter().
212 * An entity object, for instance a node object.
214 * A string identifying the target on the node.
216 * The value to populate the target with.
219 function my_module_set_target($entity, $target, $value) {
220 $entity->$target['und'][0]['value'] = $value;