Révision 41cc1b08
Ajouté par Assos Assos il y a presque 9 ans
drupal7/sites/all/modules/feeds/mappers/taxonomy.inc | ||
---|---|---|
23 | 23 |
/** |
24 | 24 |
* Implements hook_feeds_parser_sources_alter(). |
25 | 25 |
*/ |
26 |
function taxonomy_feeds_parser_sources_alter(&$sources, $content_type) { |
|
26 |
function taxonomy_feeds_parser_sources_alter(array &$sources, $content_type) {
|
|
27 | 27 |
if (!empty($content_type)) { |
28 | 28 |
foreach (taxonomy_get_vocabularies($content_type) as $vocabulary) { |
29 | 29 |
$sources['parent:taxonomy:' . $vocabulary->machine_name] = array( |
... | ... | |
55 | 55 |
} |
56 | 56 |
|
57 | 57 |
/** |
58 |
* Implements hook_feeds_processor_targets_alter().
|
|
58 |
* Implements hook_feeds_processor_targets(). |
|
59 | 59 |
*/ |
60 |
function taxonomy_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_name) { |
|
60 |
function taxonomy_feeds_processor_targets($entity_type, $bundle_name) { |
|
61 |
$targets = array(); |
|
62 |
|
|
61 | 63 |
foreach (field_info_instances($entity_type, $bundle_name) as $name => $instance) { |
62 | 64 |
$info = field_info_field($name); |
63 | 65 |
if ($info['type'] == 'taxonomy_term_reference') { |
... | ... | |
65 | 67 |
'name' => check_plain($instance['label']), |
66 | 68 |
'callback' => 'taxonomy_feeds_set_target', |
67 | 69 |
'description' => t('The @label field of the entity.', array('@label' => $instance['label'])), |
68 |
'summary_callback' => 'taxonomy_feeds_summary_callback',
|
|
69 |
'form_callback' => 'taxonomy_feeds_form_callback',
|
|
70 |
'summary_callbacks' => array('taxonomy_feeds_summary_callback'),
|
|
71 |
'form_callbacks' => array('taxonomy_feeds_form_callback'),
|
|
70 | 72 |
); |
71 | 73 |
} |
72 | 74 |
} |
75 |
if ($entity_type == 'taxonomy_term') { |
|
76 |
$targets['tid']['name'] = t('Term id'); |
|
77 |
$targets['tid']['description'] = t('The tid of the taxonomy term. NOTE: use this feature with care, node ids are usually assigned by Drupal.'); |
|
78 |
unset($targets['vocabulary']); |
|
79 |
} |
|
80 |
|
|
81 |
return $targets; |
|
73 | 82 |
} |
74 | 83 |
|
75 | 84 |
/** |
76 |
* Callback for mapping. Here is where the actual mapping happens. |
|
77 |
* |
|
78 |
* @todo Do not create new terms for non-autotag fields. |
|
85 |
* Callback for mapping taxonomy terms. |
|
79 | 86 |
*/ |
80 |
function taxonomy_feeds_set_target($source, $entity, $target, $terms, $mapping = array()) { |
|
81 |
|
|
82 |
// Allow mapping the string '0' to a term name. |
|
83 |
if (empty($terms) && $terms != 0) { |
|
84 |
return; |
|
85 |
} |
|
86 |
|
|
87 |
// Handle non-multiple values. |
|
88 |
if (!is_array($terms)) { |
|
89 |
$terms = array($terms); |
|
90 |
} |
|
91 |
|
|
87 |
function taxonomy_feeds_set_target(FeedsSource $source, $entity, $target, array $terms, array $mapping) { |
|
92 | 88 |
// Add in default values. |
93 | 89 |
$mapping += array( |
94 | 90 |
'term_search' => FEEDS_TAXONOMY_SEARCH_TERM_NAME, |
... | ... | |
110 | 106 |
} |
111 | 107 |
} |
112 | 108 |
|
109 |
// Some kind of configuration issue. Perhaps the vocabulary was deleted. |
|
110 |
// Nothing we can do about it. |
|
111 |
if (empty($cache['allowed_vocabularies'][$target])) { |
|
112 |
return; |
|
113 |
} |
|
114 |
|
|
113 | 115 |
$query = new EntityFieldQuery(); |
114 | 116 |
$query->entityCondition('entity_type', 'taxonomy_term') |
115 | 117 |
->entityCondition('bundle', $cache['allowed_vocabularies'][$target]) |
... | ... | |
139 | 141 |
|
140 | 142 |
// Lookup by name. |
141 | 143 |
case FEEDS_TAXONOMY_SEARCH_TERM_NAME: |
144 |
$term = trim($term); |
|
142 | 145 |
$name_query = clone $query; |
143 |
if ($tids = $name_query->propertyCondition('name', $term)->execute()) { |
|
144 |
$tid = key($tids['taxonomy_term']); |
|
146 |
if (strlen($term) && $tids = $name_query->propertyCondition('name', $term)->execute()) { |
|
147 |
|
|
148 |
// Find the first allowed term. |
|
149 |
foreach ($tids['taxonomy_term'] as $possible_term) { |
|
150 |
if (isset($cache['allowed_values'][$target][$possible_term->tid])) { |
|
151 |
$tid = $possible_term->tid; |
|
152 |
break; |
|
153 |
} |
|
154 |
} |
|
145 | 155 |
} |
146 |
elseif ($mapping['autocreate']) { |
|
156 |
elseif ($mapping['autocreate'] && strlen($term)) {
|
|
147 | 157 |
$term = (object) array( |
148 |
'name' => $term,
|
|
158 |
'name' => drupal_substr($term, 0, 255),
|
|
149 | 159 |
'vid' => key($cache['allowed_vocabularies'][$target]), |
150 | 160 |
'vocabulary_machine_name' => reset($cache['allowed_vocabularies'][$target]), |
151 | 161 |
); |
... | ... | |
159 | 169 |
// Lookup by tid. |
160 | 170 |
case FEEDS_TAXONOMY_SEARCH_TERM_ID: |
161 | 171 |
if (is_numeric($term)) { |
162 |
$tid = $term; |
|
172 |
$tid = (int) $term;
|
|
163 | 173 |
} |
164 | 174 |
break; |
165 | 175 |
|
... | ... | |
171 | 181 |
} |
172 | 182 |
|
173 | 183 |
if ($tid && isset($cache['allowed_values'][$target][$tid])) { |
174 |
$field['und'][$delta]['tid'] = $tid;
|
|
184 |
$field['und'][] = array('tid' => $tid);
|
|
175 | 185 |
$delta++; |
176 | 186 |
} |
177 | 187 |
} |
... | ... | |
244 | 254 |
|
245 | 255 |
/** |
246 | 256 |
* Mapping configuration summary for taxonomy.module. |
247 |
* |
|
248 |
* @param array $mapping |
|
249 |
* Associative array of the mapping settings. |
|
250 |
* @param array $target |
|
251 |
* Array of target settings, as defined by the processor or |
|
252 |
* hook_feeds_processor_targets_alter(). |
|
253 |
* @param array $form |
|
254 |
* The whole mapping form. |
|
255 |
* @param array $form_state |
|
256 |
* The form state of the mapping form. |
|
257 |
* |
|
258 |
* @return string |
|
259 |
* Returns, as a string that may contain HTML, the summary to display while |
|
260 |
* the full form isn't visible. |
|
261 |
* If the return value is empty, no summary and no option to view the form |
|
262 |
* will be displayed. |
|
263 | 257 |
*/ |
264 |
function taxonomy_feeds_summary_callback($mapping, $target, $form, $form_state) {
|
|
258 |
function taxonomy_feeds_summary_callback(array $mapping, $target, array $form, array $form_state) {
|
|
265 | 259 |
$options = _taxonomy_feeds_form_callback_options(); |
266 | 260 |
if (empty($mapping['term_search'])) { |
267 | 261 |
return t('Search taxonomy terms by: <strong>@search</strong>', array('@search' => $options[FEEDS_TAXONOMY_SEARCH_TERM_NAME])); |
... | ... | |
271 | 265 |
|
272 | 266 |
/** |
273 | 267 |
* Settings form callback. |
274 |
* |
|
275 |
* @return array |
|
276 |
* The per mapping configuration form. Once the form is saved, $mapping will |
|
277 |
* be populated with the form values. |
|
278 | 268 |
*/ |
279 |
function taxonomy_feeds_form_callback($mapping, $target, $form, $form_state) {
|
|
269 |
function taxonomy_feeds_form_callback(array $mapping, $target, array $form, array $form_state) {
|
|
280 | 270 |
return array( |
281 | 271 |
'term_search' => array( |
282 | 272 |
'#type' => 'select', |
Formats disponibles : Unified diff
Update feeds 7.x-2.0-alpha9 -> 7.x-2.0-beta1
Install lib simplepie 1.3.1