/[drupal]/contributions/modules/feedapi_mapper/feedapi_mapper.api.php
ViewVC logotype

Contents of /contributions/modules/feedapi_mapper/feedapi_mapper.api.php

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download) (as text)
Tue Jul 14 17:18:22 2009 UTC (4 months, 2 weeks ago) by alexb
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--2
Changes since 1.1: +129 -0 lines
File MIME type: text/x-php
Merge changes in DRUPAL-6--1 into HEAD.
1 <?php
2 // $Id: feedapi_mapper.api.php,v 1.1.2.3 2009/05/09 14:28:33 alexb Exp $
3
4 /**
5 * @file
6 * API documentation for Feed Element Mapper.
7 */
8
9 /**
10 * Implement hook_feedapi_mapper() to map an element of a feed to a field on a
11 * node.
12 *
13 * Mapping flow
14 *
15 * 1) hook_feedapi_mapper('list')
16 *
17 * This operation is invoked when the mapper is about to present mapping
18 * options to the user. When $op is 'list' the $node parameter contains the
19 * type of the node at $node->type, all other parameters are not present.
20 * Examine $node->type and determine which mapping targets are available.
21 *
22 * If no mapping target is available return FALSE.
23 *
24 * If a single mapping target is available return:
25 * array(
26 * 'single_target' => t('Single target'), // 'single_target' will be the value of $field_name on 'map'
27 * )
28 *
29 * If multiple mapping targets are available return:
30 * array(
31 * 'target1' => t('Target 1'), // 'target1' will be the field name on 'map'
32 * 'target2' => t('Target 2'), // 'target2' will be the field name on 'map'
33 * )
34 *
35 * Feed Element Mapper also supports sub fields:
36 * array(
37 * 'multiple_targets' => array( // 'multiple_targets' will be the value of $field_name on 'map'
38 * 'target1' => t('Target 1'), // 'target1' will be the value of $sub_field on 'map'
39 * 'target2' => t('Target 2'), // 'target2' will be the value of $sub_field on 'map'
40 * )
41 * )
42 *
43 *
44 * 2) hook_feedapi_mapper('map')
45 *
46 * This operation is invoked when the actual mapping happens. If a user
47 * selected the mapping functionality exposed on 'list' hook_feedapi_mapper
48 * will be called on node prepare with $op == 'map', $node = feed item node the
49 * mapping is performed on, $feed_element = the element of the feed that a user
50 * chose as a mapping source, $field_name = the name of the field that a user
51 * chose as a mapping target, $sub_field = the name of the sub field that a user
52 * chose as a mapping target.
53 *
54 *
55 * hook_feedapi_mapper('describe') is used to generate help text on the
56 * mapping form.
57 *
58 * Which feed elements are available for mapping is up to the parser.
59 *
60 * @param $op
61 * Operation to perform.
62 * Value of $op is one of 'describe', 'list' or 'map'.
63 * @param $node
64 * Drupal node object.
65 * @param $feed_element
66 * Parameter only present on $op = 'map'
67 * Element of the feed to map from. A simple data type (number, string) or a
68 * one dimensional array of simple types.
69 * @param $field_name
70 * Parameter only present on $op = 'map'
71 * Name of the field to map to.
72 * @param $sub_field
73 * Parameter only present on $op = 'map'
74 * If given, a subfield on the node to map to.
75 * This parameter will depend on if the hook implementation returns a subfield on
76 * $op = 'list'.
77 *
78 */
79 function hook_feedapi_mapper($op, $node, $feed_element = array(), $field_name = '', $sub_field = '') {
80 if ($op == 'describe') {
81 return t('Maps a string or an array of strings to myfields.');
82 }
83 else if ($op == 'list') {
84 if ($myfields = myfields_get_available_fields()) {
85 return $myfields;
86 }
87 return FALSE;
88 }
89 else if ($op == 'map') {
90 if ($field_name == 'myfield') {
91 if (is_string($feed_element)) {
92 $node->myfields = array ($feed_element);
93 }
94 if (is_array($feed_element)) {
95 $node->myfields[$subfield] = $feed_element;
96 }
97 return $node;
98 }
99 }
100 }
101
102 /**
103 * Implement hook_feedapi_mapper_elements to define standard elements that your
104 * configuration should be able to map to.
105 *
106 * When FeedAPI Mapper exposes the mapping form on a feed node (node/%/map), it
107 * parses the feed and uses the result to make elements of it available as
108 * mapping sources.
109 *
110 * However, when FeedAPI mapper exposes the mapping form on a content type
111 * form (admin/content/node-type/%/map), there is no feed to parse for
112 * discovering feed elements. In this case FeedAPI Mapper exposes some standard
113 * elements. You may find yourself in the need for more specific standard
114 * elements on the content type level, in this case implement
115 * hook_feedapi_mapper_elements() in your module.
116 *
117 * @see _feedapi_mapper_get_standard_elements().
118 *
119 * @return
120 * An array of arrays that describe the path to a feed element on a feed.
121 */
122 function hook_feedapi_mapper_elements() {
123 return array(
124 array('options', 'raw', 'headquarter', 'name'),
125 array('options', 'raw', 'headquarter', 'city'),
126 array('options', 'raw', 'headquarter', 'street'),
127 array('options', 'raw', 'headquarter', 'country'),
128 );
129 }

  ViewVC Help
Powered by ViewVC 1.1.2