Mercurial > hg > drupalISMI
comparison openmindattribute/openmindattribute.module @ 0:124ef8f3b22d
initial
author | Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de> |
---|---|
date | Fri, 27 Mar 2015 19:21:42 +0100 |
parents | |
children | f651752ee9ad |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:124ef8f3b22d |
---|---|
1 <?php | |
2 | |
3 | |
4 | |
5 /** | |
6 * Implements hook_field_info(). | |
7 */ | |
8 function openmindattribute_field_info() { | |
9 return array( | |
10 'openmindattribute_field' => array( | |
11 'label' => t('Attribute'), | |
12 'description' => t('The attribute'), | |
13 'default_widget' => 'openmindattribute_field', | |
14 'default_formatter' => 'openmindattribute_default', | |
15 // Support hook_entity_property_info() from contrib "Entity API". | |
16 'property_type' => 'field_item_openmindattribute', | |
17 'property_callbacks' => array('openmindattribute_field_property_info_callback') | |
18 ), | |
19 'openmindattribute_fields' => array( | |
20 'label' => t('All Attributes'), | |
21 'description' => t('The attributes'), | |
22 'default_widget' => 'openmindattribute_fields', | |
23 'default_formatter' => 'openmindattribute_default', | |
24 // Support hook_entity_property_info() from contrib "Entity API". | |
25 #'property_type' => 'field_item_openmindattribute', | |
26 #'property_callbacks' => array('openmindattribute_field_property_info_callback') | |
27 ), | |
28 'openmindattribute_field' => array( | |
29 'label' => t('Attribute'), | |
30 'description' => t('The attribute'), | |
31 'default_widget' => 'openmindattribute_field', | |
32 'default_formatter' => 'openmindattribute_default', | |
33 // Support hook_entity_property_info() from contrib "Entity API". | |
34 'property_type' => 'field_item_openmindattribute', | |
35 'property_callbacks' => array('openmindattribute_field_property_info_callback') | |
36 ), | |
37 | |
38 ); | |
39 } | |
40 | |
41 /** | |
42 * Implements hook_field_instance_settings_form(). | |
43 */ | |
44 function openmindattribute_field_instance_settings_form($field, $instance) { | |
45 | |
46 if ($field['type'] == 'openmindattribute_fields'){ // nur ausgabe feld! | |
47 $form['name'] = array( | |
48 '#type' => 'textfield', | |
49 '#title' => t('Name'), | |
50 '#default_value' => isset($instance['settings']['name']) ? $instance['settings']['name'] : '', | |
51 '#description' => t('This title will always be used if “Static Title” is selected above.'), | |
52 ); | |
53 return $form; | |
54 } | |
55 $form = array( | |
56 '#element_validate' => array('openmindattribute_field_settings_form_validate'), | |
57 ); | |
58 | |
59 | |
60 | |
61 $form['name'] = array( | |
62 '#type' => 'textfield', | |
63 '#title' => t('Name'), | |
64 '#default_value' => isset($instance['settings']['name']) ? $instance['settings']['name'] : '', | |
65 '#description' => t('This title will always be used if “Static Title” is selected above.'), | |
66 ); | |
67 | |
68 | |
69 | |
70 | |
71 | |
72 $form['ov'] = array( | |
73 '#type' => 'textfield', | |
74 '#title' => t('Ov'), | |
75 '#description' => t('Value'), | |
76 #'#default_value' => empty($instance['settings']['attributes']['rel']) ? '' : $instance['settings']['attributes']['rel'], | |
77 #'#field_prefix' => 'rel = "', | |
78 #'#field_suffix' => '"', | |
79 '#size' => 100, | |
80 ); | |
81 | |
82 $form['nov'] = array( | |
83 '#type' => 'textfield', | |
84 '#title' => t('Nov'), | |
85 '#description' => t('Normalised Value'), | |
86 #'#default_value' => empty($instance['settings']['attributes']['rel']) ? '' : $instance['settings']['attributes']['rel'], | |
87 #'#field_prefix' => 'rel = "', | |
88 #'#field_suffix' => '"', | |
89 '#size' => 100, | |
90 ); | |
91 | |
92 $form['romanization'] = array( | |
93 '#type' => 'textfield', | |
94 '#title' => t('Romanization'), | |
95 '#description' => t('Normalised Value (LOC)'), | |
96 #'#default_value' => empty($instance['settings']['attributes']['rel']) ? '' : $instance['settings']['attributes']['rel'], | |
97 #'#field_prefix' => 'rel = "', | |
98 #'#field_suffix' => '"', | |
99 '#size' => 100, | |
100 ); | |
101 | |
102 | |
103 return $form; | |
104 } | |
105 | |
106 /** | |
107 * #element_validate handler for openmindattribute_field_instance_settings_form(). | |
108 */ | |
109 function openmindattribute_field_settings_form_validate($element, &$form_state, $complete_form) { | |
110 return true; | |
111 } | |
112 | |
113 /** | |
114 * Implements hook_field_is_empty(). | |
115 */ | |
116 function openmindattribute_field_is_empty($item, $field) { | |
117 return false; | |
118 } | |
119 | |
120 #/** | |
121 # * Implements hook_field_load(). | |
122 # */ | |
123 #function link_field_load($entity_type, $entities, $field, $instances, $langcode, &$items, $age) { | |
124 # foreach ($entities as $id => $entity) { | |
125 # foreach ($items[$id] as $delta => $item) { | |
126 # $items[$id][$delta]['attributes'] = _link_load($field, $item, $instances[$id]); | |
127 # } | |
128 # } | |
129 #} | |
130 | |
131 /** | |
132 * Implements hook_field_validate(). | |
133 */ | |
134 function openmindattribute_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) { | |
135 return true; | |
136 } | |
137 | |
138 | |
139 | |
140 /** | |
141 * Implements hook_field_insert(). | |
142 */ | |
143 function openmindattribute_field_insert($entity_type, $entity, $field, $instance, $langcode, &$items) { | |
144 foreach ($items as $delta => $value) { | |
145 _openmindattribute_process($items[$delta], $delta, $field, $entity); | |
146 } | |
147 } | |
148 | |
149 /** | |
150 * Implements hook_field_update(). | |
151 */ | |
152 function openmindattribute_field_update($entity_type, $entity, $field, $instance, $langcode, &$items) { | |
153 foreach ($items as $delta => $value) { | |
154 _openmindattribute_process($items[$delta], $delta, $field, $entity); | |
155 } | |
156 } | |
157 | |
158 #/** | |
159 # * Implements hook_field_prepare_view(). | |
160 #*/ | |
161 #function openmindattribute_field_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items) { | |
162 # foreach ($items as $entity_id => $entity_items) { | |
163 # foreach ($entity_items as $delta => $value) { | |
164 # _link_sanitize($items[$entity_id][$delta], $delta, $field, $instances[$entity_id], $entities[$entity_id]); | |
165 # } | |
166 # } | |
167 #} | |
168 | |
169 /** | |
170 * Implements hook_field_widget_info(). | |
171 */ | |
172 function openmindattribute_field_widget_info() { | |
173 return array( | |
174 'openmindattribute_field' => array( | |
175 'label' => 'Attribute', | |
176 'field types' => array('openmindattribute_field'), | |
177 'multiple values' => FIELD_BEHAVIOR_DEFAULT, | |
178 ), | |
179 'openmindattribute_fields' => array( | |
180 'label' => 'NOTHING', | |
181 'field types' => array('openmindattribute_fields'), | |
182 'multiple values' => FIELD_BEHAVIOR_NONE | |
183 ), | |
184 ); | |
185 } | |
186 | |
187 /** | |
188 * Implements hook_field_widget_form(). | |
189 */ | |
190 function openmindattribute_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) { | |
191 | |
192 | |
193 if ($field['type'] == 'openmindattribute_fields'){ // nur ausgabe feld! | |
194 return $element; | |
195 } | |
196 $element += array( | |
197 '#type' => $instance['widget']['type'], | |
198 '#default_value' => isset($items[$delta]) ? $items[$delta] : '', | |
199 ); | |
200 return $element; | |
201 } | |
202 | |
203 #/** | |
204 # * Implements hook_field_widget_error(). | |
205 # */ | |
206 #function link_field_widget_error($element, $error, $form, &$form_state) { | |
207 # if ($error['error_element']['title']) { | |
208 # form_error($element['title'], $error['message']); | |
209 # } | |
210 # elseif ($error['error_element']['url']) { | |
211 # form_error($element['url'], $error['message']); | |
212 # } | |
213 #} | |
214 | |
215 | |
216 /** | |
217 * Prepares the item attributes and url for storage. | |
218 */ | |
219 function _openmindattribute_process(&$item, $delta = 0, $field, $entity) { | |
220 // Trim whitespace from URL. | |
221 $item['name'] = trim($item['name']); | |
222 } | |
223 | |
224 | |
225 | |
226 | |
227 /** | |
228 * Implements hook_theme(). | |
229 */ | |
230 function openmindattribute_theme() { | |
231 return array( | |
232 'openmindattribute_formatter_default' => array( | |
233 'variables' => array('element' => NULL, 'field' => NULL, 'entity' => NULL), | |
234 ), | |
235 'openmindattribute_formatter_fields_default' => array( | |
236 'variables' => array('type' => NULL, 'attributes' => NULL), | |
237 ), | |
238 'openmindattribute_formatter_fields_specialized' => array( | |
239 'variables' => array('type' => NULL, 'attributes' => NULL), | |
240 ), | |
241 'openmindattribute_formatter_field_identifier' => array( | |
242 'variables' => array('type' => NULL, 'attributes' => NULL), | |
243 ), | |
244 | |
245 'openmindattribute_formatter_field_full_title' => array( | |
246 'variables' => array('type' => NULL, 'attributes' => NULL), | |
247 ), | |
248 | |
249 | |
250 'openmindattribute_formatter_field_full_title_translit_romanization' => array( | |
251 'variables' => array('type' => NULL, 'attributes' => NULL), | |
252 ), | |
253 | |
254 | |
255 'openmindattribute_formatter_field_name_translit_romanization' => array( | |
256 'variables' => array('type' => NULL, 'attributes' => NULL), | |
257 ), | |
258 | |
259 'openmindattribute_formatter_field_name' => array( | |
260 'variables' => array('type' => NULL, 'attributes' => NULL, 'nid' => NULL), | |
261 ), | |
262 | |
263 'openmindattribute_formatter_field_ahlwardt' => array( | |
264 'variables' => array('type' => NULL, 'attributes' => NULL), | |
265 ), | |
266 | |
267 'openmindattribute_formatter_fields_diva_link' => array( | |
268 'variables' => array('type' => NULL,'entid' => NULL) | |
269 ), | |
270 | |
271 'openmindattribute_formatter_field_MPIWG_viewer' => array( | |
272 'variables' => array('type' => NULL, 'attributes' => NULL), | |
273 ), | |
274 'openmindattribute_item_thumbnail' => array( | |
275 'variables' => array('objid' => NULL,'entid' => NULL,'objdata'=>NULL,'type'=>NULL), | |
276 | |
277 ), | |
278 | |
279 | |
280 'openmindattribute_reference_format' => array ( | |
281 'variables' => array('type' => NULL,'entid' => NULL, 'attributes' => NULL, 'ov' => NULL, 'nid' => NULL ), | |
282 | |
283 ), | |
284 | |
285 | |
286 | |
287 | |
288 | |
289 ); | |
290 } | |
291 | |
292 function theme_openmindattribute_item_thumbnail($vars) { | |
293 | |
294 $vars['objdata'] = digitalobjects_readMetadata($vars['objid']); | |
295 | |
296 return theme_render_template(drupal_get_path('module', 'openmindattribute') . "/templates/openmindattribute-item-thumbnail.tpl.php", $vars); | |
297 | |
298 } | |
299 | |
300 | |
301 function theme_openmindattribute_reference_format($vars){ | |
302 | |
303 return theme_render_template(drupal_get_path('module', 'openmindattribute') . "/templates/openmindattribute_reference_format.tpl.php", $vars); | |
304 | |
305 } | |
306 | |
307 /** | |
308 * Formats a link field widget. | |
309 */ | |
310 function theme_openmindattribute_field($vars) { | |
311 drupal_add_css(drupal_get_path('module', 'openmindattribute') . '/openmindattribute.css'); | |
312 $element = $vars['element']; | |
313 // Prefix single value link fields with the name of the field. | |
314 | |
315 | |
316 $output = ''; | |
317 $output .= '<div class="openmindattribute-field-subrow clearfix">'; | |
318 $output = $output . $element['name']; | |
319 $output = $output . $element['ov']; | |
320 $output = $output . $element['nov']; | |
321 $output = $output . $element['romanization']; | |
322 | |
323 return $output; | |
324 } | |
325 | |
326 /** | |
327 * Implements hook_element_info(). | |
328 */ | |
329 function openmindattribute_element_info() { | |
330 $elements = array(); | |
331 $elements['openmindattribute_field'] = array( | |
332 '#input' => TRUE, | |
333 '#process' => array('openmindattribute_field_process'), | |
334 '#theme' => 'openmindattribute_field', | |
335 '#theme_wrappers' => array('form_element'), | |
336 ); | |
337 return $elements; | |
338 } | |
339 | |
340 | |
341 | |
342 /** | |
343 * Processes the link type element before displaying the field. | |
344 * | |
345 * Build the form element. When creating a form using FAPI #process, | |
346 * note that $element['#value'] is already set. | |
347 * | |
348 * The $fields array is in $complete_form['#field_info'][$element['#field_name']]. | |
349 */ | |
350 function openmindattribute_field_process($element, $form_state, $complete_form) { | |
351 | |
352 $instance = field_widget_instance($element, $form_state); | |
353 | |
354 $settings = $instance['settings']; | |
355 $element['name'] = array( | |
356 '#type' => 'textfield', | |
357 '#maxlength' => 1000, | |
358 '#title' => t('name'), | |
359 '#required' => FALSE, | |
360 '#default_value' => isset($element['#value']['name']) ? $element['#value']['name'] : NULL, | |
361 ); | |
362 | |
363 $element['ov'] = array( | |
364 '#type' => 'textfield', | |
365 '#maxlength' => 1000, | |
366 '#title' => t('ov'), | |
367 '#required' => FALSE, | |
368 '#default_value' => isset($element['#value']['ov']) ? $element['#value']['ov'] : NULL, | |
369 ); | |
370 | |
371 $element['nov'] = array( | |
372 '#type' => 'textfield', | |
373 '#maxlength' => 1000, | |
374 '#title' => t('nov'), | |
375 '#required' => FALSE, | |
376 '#default_value' => isset($element['#value']['nov']) ? $element['#value']['nov'] : NULL, | |
377 ); | |
378 | |
379 $element['romanization'] = array( | |
380 '#type' => 'textfield', | |
381 '#maxlength' => 1000, | |
382 '#title' => t('romanization'), | |
383 '#required' => FALSE, | |
384 '#default_value' => isset($element['#value']['romanization']) ? $element['#value']['romanization'] : NULL, | |
385 ); | |
386 | |
387 | |
388 | |
389 return $element; | |
390 } | |
391 | |
392 /** | |
393 * Implements hook_field_formatter_info(). | |
394 */ | |
395 function openmindattribute_field_formatter_info() { | |
396 return array( | |
397 | |
398 | |
399 'openmindattribute_reference_format' => array( | |
400 'label' => t('Formats a title field with the field selected, depending on the value of oc'), | |
401 'field types' => array('text'), | |
402 'multiple values' => FIELD_BEHAVIOR_DEFAULT, | |
403 ), | |
404 | |
405 'openmindattribute_default' => array( | |
406 'label' => t('Attribute as default'), | |
407 'field types' => array('openmindattribute_field'), | |
408 'multiple values' => FIELD_BEHAVIOR_DEFAULT, | |
409 ), | |
410 'openmindattribute_fields_default' => array( | |
411 'label' => t('All Attribute as default'), | |
412 'field types' => array('openmindattribute_fields'), | |
413 'multiple values' => FIELD_BEHAVIOR_DEFAULT, | |
414 ), | |
415 'openmindattribute_fields_specialized' => array( | |
416 'label' => t('All Attribute as specialized'), | |
417 'field types' => array('openmindattribute_fields'), | |
418 'multiple values' => FIELD_BEHAVIOR_DEFAULT, | |
419 ), | |
420 'openmindattribute_fields_diva_link' => array( | |
421 'label' => t('DIVA-openmind-view'), | |
422 'field types' => array('text'), | |
423 'multiple values' => FIELD_BEHAVIOR_DEFAULT, | |
424 ), | |
425 'openmindattribute_field_identifier' => array( | |
426 'label' => t('Only the attribute identifer'), | |
427 'field types' => array('openmindattribute_fields'), | |
428 'multiple values' => FIELD_BEHAVIOR_DEFAULT, | |
429 ), | |
430 | |
431 'openmindattribute_field_full_title' => array( | |
432 'label' => t('Only the attribute full_title'), | |
433 'field types' => array('openmindattribute_fields'), | |
434 'multiple values' => FIELD_BEHAVIOR_DEFAULT, | |
435 ), | |
436 | |
437 'openmindattribute_field_full_title_translit_romanization' => array( | |
438 'label' => t('Only the attribute full_title_translit_romanization'), | |
439 'field types' => array('openmindattribute_fields'), | |
440 'multiple values' => FIELD_BEHAVIOR_DEFAULT, | |
441 ), | |
442 | |
443 'openmindattribute_field_name_translit_romanization' => array( | |
444 'label' => t('Only the attribute name_translit_romanization'), | |
445 'field types' => array('openmindattribute_fields'), | |
446 'multiple values' => FIELD_BEHAVIOR_DEFAULT, | |
447 ), | |
448 | |
449 'openmindattribute_field_ahlwardt' => array( | |
450 'label' => t('Only the attribute ahlwardt'), | |
451 'field types' => array('openmindattribute_fields'), | |
452 'multiple values' => FIELD_BEHAVIOR_DEFAULT, | |
453 ), | |
454 | |
455 'openmindattribute_field_name' => array( | |
456 'label' => t('Only the attribute name'), | |
457 'field types' => array('openmindattribute_fields'), | |
458 'multiple values' => FIELD_BEHAVIOR_DEFAULT, | |
459 ), | |
460 | |
461 | |
462 | |
463 'openmindattribute_field_MPIWG_viewer' => array( | |
464 'label' => t('MPIWG Image viewer'), | |
465 'field types' => array('openmindattribute_fields'), | |
466 'multiple values' => FIELD_BEHAVIOR_DEFAULT, | |
467 ), | |
468 'openmindattribute_field_MPIWG_viewer_for_view' => array( | |
469 'label' => t('MPIWG Image viewer (for use in views)'), | |
470 'field types' => array('openmindattribute_fields'), | |
471 'multiple values' => FIELD_BEHAVIOR_DEFAULT, | |
472 ), | |
473 | |
474 | |
475 ); | |
476 } | |
477 | |
478 #/** | |
479 # * Implements hook_field_formatter_settings_form(). | |
480 # */ | |
481 #function openmindattribute_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) { | |
482 # $display = $instance['display'][$view_mode]; | |
483 # $settings = $display['settings']; | |
484 # $element = array(); | |
485 # if ($display['type'] == 'link_domain') { | |
486 # $element['strip_www'] = array( | |
487 # '#title' => t('Strip www. from domain'), | |
488 # '#type' => 'checkbox', | |
489 # '#default_value' => $settings['strip_www'], | |
490 # ); | |
491 ## } | |
492 # return $element; | |
493 #} | |
494 | |
495 #/** | |
496 # * Implements hook_field_formatter_settings_summary(). | |
497 # */ | |
498 #function link_field_formatter_settings_summary($field, $instance, $view_mode) { | |
499 # $display = $instance['display'][$view_mode]; | |
500 # $settings = $display['settings']; | |
501 # if ($display['type'] == 'link_domain') { | |
502 # if ($display['settings']['strip_www']) { | |
503 # return t('Strip www. from domain'); | |
504 # } | |
505 ## else { | |
506 # return t('Leave www. in domain'); | |
507 # } | |
508 # } | |
509 # return ''; | |
510 #} | |
511 | |
512 | |
513 function _openmindattribute_field_remap($atts){ | |
514 //erzeuge eine array mit name -> (ov, nov,name) | |
515 $retmap = array(); | |
516 foreach ($atts as $a){ | |
517 $retmap[$a['name']]=$a; | |
518 } | |
519 return $retmap; | |
520 } | |
521 | |
522 | |
523 | |
524 | |
525 | |
526 /** | |
527 * Implements hook_field_formatter_view(). | |
528 */ | |
529 function openmindattribute_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) { | |
530 | |
531 | |
532 #openmindattribute_fields ist nur experimentell, TODO: insbesondere field_oc, field_attribute sollte nicht hardcoded vorliegen. | |
533 | |
534 $elements= array(); | |
535 | |
536 if ($field['type'] == 'text'){ // nur ausgabe feld! | |
537 | |
538 | |
539 | |
540 switch($display['type']){ | |
541 | |
542 | |
543 case ("openmindattribute_fields_diva_link"): | |
544 | |
545 foreach ($items as $delta => $item) { | |
546 $entid = $entity->field_id['und'][0]['value']; | |
547 | |
548 $ocid = $entity->field_oc['und'][0]['tid']; | |
549 | |
550 $term = taxonomy_term_load($ocid); | |
551 | |
552 | |
553 $elements[$delta] = array( | |
554 '#theme' => 'openmindattribute_formatter_fields_diva_link', | |
555 '#entid' => $entid, | |
556 '#type' => $term->name | |
557 | |
558 ); | |
559 } | |
560 | |
561 return $elements; | |
562 | |
563 | |
564 break; | |
565 | |
566 case ("openmindattribute_reference_format"): | |
567 | |
568 foreach ($items as $delta => $item) { | |
569 $entid = $entity->field_id['und'][0]['value']; | |
570 | |
571 $ocid = $entity->field_oc['und'][0]['tid']; | |
572 | |
573 $term = taxonomy_term_load($ocid); | |
574 | |
575 | |
576 $atts = $entity->field_attribute['und']; | |
577 | |
578 $atts_mapped = _openmindattribute_field_remap($atts); | |
579 | |
580 | |
581 | |
582 | |
583 | |
584 $elements[$delta] = array( | |
585 '#theme' => 'openmindattribute_reference_format', | |
586 '#entid' => $entid, | |
587 '#type' => $term->name, | |
588 '#attributes' => $atts_mapped, | |
589 '#ov' =>$entity->field_ov['und'][0]['value'], | |
590 '#nid' => $entity->nid | |
591 | |
592 | |
593 ); | |
594 } | |
595 | |
596 return $elements; | |
597 } | |
598 | |
599 | |
600 | |
601 | |
602 | |
603 | |
604 } | |
605 | |
606 | |
607 if ($field['type'] == 'openmindattribute_fields'){ // nur ausgabe feld! | |
608 | |
609 switch($display['type']){ | |
610 | |
611 | |
612 case ("openmindattribute_fields_specialized"): | |
613 | |
614 | |
615 $ocid = $entity->field_oc['und'][0]['tid']; | |
616 | |
617 $term = taxonomy_term_load($ocid); | |
618 | |
619 | |
620 $atts = $entity->field_attribute['und']; | |
621 | |
622 $atts_mapped = _openmindattribute_field_remap($atts); | |
623 | |
624 | |
625 $elements = array( | |
626 '#theme' => 'openmindattribute_formatter_fields_specialized', | |
627 '#attributes' => $atts_mapped, | |
628 '#type' => $term->name | |
629 ); | |
630 | |
631 break; | |
632 | |
633 case ("openmindattribute_fields_default"): | |
634 | |
635 | |
636 $ocid = $entity->field_oc['und'][0]['tid']; | |
637 | |
638 $term = taxonomy_term_load($ocid); | |
639 | |
640 | |
641 | |
642 $elements = array( | |
643 '#theme' => 'openmindattribute_formatter_fields_default', | |
644 '#attributes' => $entity->field_attribute['und'], | |
645 '#type' => $term->name | |
646 ); | |
647 | |
648 break; | |
649 | |
650 // show only the identifier TODO only preliminary should define a formatter where you can configure the field | |
651 | |
652 | |
653 case ("openmindattribute_field_identifier"): | |
654 | |
655 //foreach ($items as $delta => $item) { | |
656 $ocid = $entity->field_oc['und'][0]['tid']; | |
657 | |
658 $term = taxonomy_term_load($ocid); | |
659 | |
660 | |
661 $atts = $entity->field_attribute['und']; | |
662 | |
663 $atts_mapped = _openmindattribute_field_remap($atts); | |
664 | |
665 | |
666 $output = array( | |
667 '#theme' => 'openmindattribute_formatter_field_identifier', | |
668 '#attributes' => $atts_mapped, | |
669 '#type' => $term->name, | |
670 ); | |
671 | |
672 $elements[] = $output; | |
673 | |
674 //} | |
675 | |
676 | |
677 //$elements[$delta] = array ('#markup' => render($element_tmp)); | |
678 //} | |
679 break; | |
680 | |
681 case ("openmindattribute_field_full_title"): | |
682 | |
683 //foreach ($items as $delta => $item) { | |
684 $ocid = $entity->field_oc['und'][0]['tid']; | |
685 | |
686 $term = taxonomy_term_load($ocid); | |
687 | |
688 | |
689 $atts = $entity->field_attribute['und']; | |
690 | |
691 $atts_mapped = _openmindattribute_field_remap($atts); | |
692 | |
693 | |
694 $output = array( | |
695 '#theme' => 'openmindattribute_formatter_field_full_title', | |
696 '#attributes' => $atts_mapped, | |
697 '#type' => $term->name, | |
698 ); | |
699 | |
700 $elements[] = $output; | |
701 | |
702 //} | |
703 | |
704 | |
705 //$elements[$delta] = array ('#markup' => render($element_tmp)); | |
706 //} | |
707 break; | |
708 | |
709 | |
710 case ("openmindattribute_field_full_title_translit_romanization"): | |
711 | |
712 //foreach ($items as $delta => $item) { | |
713 $ocid = $entity->field_oc['und'][0]['tid']; | |
714 | |
715 $term = taxonomy_term_load($ocid); | |
716 | |
717 | |
718 $atts = $entity->field_attribute['und']; | |
719 | |
720 $atts_mapped = _openmindattribute_field_remap($atts); | |
721 | |
722 | |
723 $output = array( | |
724 '#theme' => 'openmindattribute_formatter_field_full_title_translit_romanization', | |
725 '#attributes' => $atts_mapped, | |
726 '#type' => $term->name, | |
727 ); | |
728 | |
729 $elements[] = $output; | |
730 | |
731 //} | |
732 | |
733 | |
734 //$elements[$delta] = array ('#markup' => render($element_tmp)); | |
735 //} | |
736 break; | |
737 | |
738 | |
739 case ("openmindattribute_field_name_translit_romanization"): | |
740 | |
741 //foreach ($items as $delta => $item) { | |
742 $ocid = $entity->field_oc['und'][0]['tid']; | |
743 | |
744 $term = taxonomy_term_load($ocid); | |
745 | |
746 | |
747 $atts = $entity->field_attribute['und']; | |
748 | |
749 $atts_mapped = _openmindattribute_field_remap($atts); | |
750 | |
751 | |
752 $output = array( | |
753 '#theme' => 'openmindattribute_formatter_field_name_translit_romanization', | |
754 '#attributes' => $atts_mapped, | |
755 '#type' => $term->name, | |
756 ); | |
757 | |
758 $elements[] = $output; | |
759 | |
760 //} | |
761 | |
762 | |
763 //$elements[$delta] = array ('#markup' => render($element_tmp)); | |
764 //} | |
765 break; | |
766 case ("openmindattribute_field_name"): | |
767 | |
768 //foreach ($items as $delta => $item) { | |
769 $ocid = $entity->field_oc['und'][0]['tid']; | |
770 | |
771 $term = taxonomy_term_load($ocid); | |
772 | |
773 | |
774 $atts = $entity->field_attribute['und']; | |
775 | |
776 $atts_mapped = _openmindattribute_field_remap($atts); | |
777 | |
778 | |
779 $nid = $entity->nid; | |
780 | |
781 $output = array( | |
782 '#theme' => 'openmindattribute_formatter_field_name', | |
783 '#attributes' => $atts_mapped, | |
784 '#type' => $term->name, | |
785 '#nid' => $nid | |
786 ); | |
787 | |
788 $elements[] = $output; | |
789 | |
790 //} | |
791 | |
792 | |
793 //$elements[$delta] = array ('#markup' => render($element_tmp)); | |
794 //} | |
795 break; | |
796 | |
797 | |
798 case ("openmindattribute_field_ahlwardt"): | |
799 | |
800 //foreach ($items as $delta => $item) { | |
801 $ocid = $entity->field_oc['und'][0]['tid']; | |
802 | |
803 $term = taxonomy_term_load($ocid); | |
804 | |
805 | |
806 $atts = $entity->field_attribute['und']; | |
807 | |
808 $atts_mapped = _openmindattribute_field_remap($atts); | |
809 | |
810 | |
811 $output = array( | |
812 '#theme' => 'openmindattribute_formatter_field_ahlwardt', | |
813 '#attributes' => $atts_mapped, | |
814 '#type' => $term->name, | |
815 ); | |
816 | |
817 $elements[] = $output; | |
818 | |
819 //} | |
820 | |
821 | |
822 //$elements[$delta] = array ('#markup' => render($element_tmp)); | |
823 //} | |
824 break; | |
825 | |
826 case ("openmindattribute_field_MPIWG_viewer"): | |
827 | |
828 | |
829 $ocid = $entity->field_oc['und'][0]['tid']; | |
830 | |
831 $term = taxonomy_term_load($ocid); | |
832 | |
833 | |
834 $atts = $entity->field_attribute['und']; | |
835 | |
836 $atts_mapped = _openmindattribute_field_remap($atts); | |
837 | |
838 | |
839 if (isset($atts_mapped['mpiwg_id']['ov'])){ | |
840 | |
841 $elements = array( | |
842 '#theme' => 'digitalobjects_item_thumbnail', | |
843 '#objid' => strtoupper($atts_mapped['mpiwg_id']['ov']), | |
844 | |
845 | |
846 | |
847 ); | |
848 | |
849 | |
850 } | |
851 | |
852 break; | |
853 | |
854 case ("openmindattribute_field_MPIWG_viewer_for_view"): | |
855 | |
856 | |
857 | |
858 | |
859 | |
860 | |
861 $ocid = $entity->field_oc['und'][0]['tid']; | |
862 | |
863 $term = taxonomy_term_load($ocid); | |
864 | |
865 | |
866 $atts = $entity->field_attribute['und']; | |
867 | |
868 $atts_mapped = _openmindattribute_field_remap($atts); | |
869 | |
870 $entid = $entity->field_id['und'][0]['value']; | |
871 | |
872 if (isset($atts_mapped['mpiwg_id']['ov'])){ | |
873 | |
874 $elements[] = array( | |
875 '#theme' => 'openmindattribute_item_thumbnail', | |
876 '#objid' => strtoupper($atts_mapped['mpiwg_id']['ov']), | |
877 '#entid' => $entid, | |
878 '#type' => $term->name, | |
879 | |
880 | |
881 | |
882 ); | |
883 | |
884 | |
885 } | |
886 | |
887 break; | |
888 | |
889 | |
890 } | |
891 | |
892 | |
893 return $elements; | |
894 } else { | |
895 | |
896 | |
897 $elements = array(); | |
898 | |
899 | |
900 foreach ($items as $delta => $item) { | |
901 $elements[$delta] = array( | |
902 '#theme' => 'openmindattribute_formatter_default', | |
903 '#element' => $item, | |
904 '#field' => $instance, | |
905 '#display' => $display, | |
906 '#entity' => $entity | |
907 ); | |
908 } | |
909 return $elements; | |
910 } | |
911 } | |
912 | |
913 /** | |
914 * Formats a link. | |
915 */ | |
916 function theme_openmindattribute_formatter_default($vars) { | |
917 | |
918 | |
919 $entity = $vars['type']; | |
920 | |
921 | |
922 $ocid = $entity->field_oc['und'][0]['tid']; | |
923 | |
924 | |
925 $term = taxonomy_term_load($ocid); | |
926 | |
927 | |
928 | |
929 return $vars['element']['name'] . $vars['element']['ov'] . $vars['element']['nov'] . $vars['element']['romanization']; | |
930 | |
931 } | |
932 | |
933 function theme_openmindattribute_formatter_fields_specialized($vars) { | |
934 | |
935 $type = $vars['type']; | |
936 | |
937 | |
938 return theme_render_template(drupal_get_path('module', 'openmindattribute') . "/templates/openmindattribute_" . $type . ".tpl.php", $vars); | |
939 | |
940 | |
941 | |
942 | |
943 | |
944 | |
945 } | |
946 | |
947 | |
948 | |
949 function theme_openmindattribute_formatter_field_identifier($vars) { | |
950 | |
951 $type = $vars['type']; | |
952 | |
953 | |
954 return theme_render_template(drupal_get_path('module', 'openmindattribute') . "/templates/openmindattribute_identifier.tpl.php", $vars); | |
955 | |
956 | |
957 | |
958 | |
959 } | |
960 | |
961 | |
962 function theme_openmindattribute_formatter_field_full_title($vars) { | |
963 | |
964 $type = $vars['type']; | |
965 | |
966 | |
967 return theme_render_template(drupal_get_path('module', 'openmindattribute') . "/templates/openmindattribute_full_title.tpl.php", $vars); | |
968 | |
969 | |
970 | |
971 | |
972 } | |
973 | |
974 | |
975 | |
976 function theme_openmindattribute_formatter_field_full_title_translit_romanization($vars) { | |
977 | |
978 $type = $vars['type']; | |
979 | |
980 | |
981 return theme_render_template(drupal_get_path('module', 'openmindattribute') . "/templates/openmindattribute_full_title_translit_romanization.tpl.php", $vars); | |
982 | |
983 | |
984 | |
985 | |
986 } | |
987 | |
988 function theme_openmindattribute_formatter_field_name_translit_romanization($vars) { | |
989 | |
990 $type = $vars['type']; | |
991 | |
992 | |
993 return theme_render_template(drupal_get_path('module', 'openmindattribute') . "/templates/openmindattribute_name_translit_romanization.tpl.php", $vars); | |
994 | |
995 | |
996 | |
997 | |
998 } | |
999 | |
1000 | |
1001 | |
1002 function theme_openmindattribute_formatter_field_name($vars) { | |
1003 | |
1004 $type = $vars['type']; | |
1005 | |
1006 | |
1007 return theme_render_template(drupal_get_path('module', 'openmindattribute') . "/templates/openmindattribute_name.tpl.php", $vars); | |
1008 | |
1009 | |
1010 | |
1011 | |
1012 } | |
1013 | |
1014 | |
1015 | |
1016 function theme_openmindattribute_formatter_field_ahlwardt($vars) { | |
1017 | |
1018 $type = $vars['type']; | |
1019 | |
1020 | |
1021 return theme_render_template(drupal_get_path('module', 'openmindattribute') . "/templates/openmindattribute_ahlwardt.tpl.php", $vars); | |
1022 | |
1023 | |
1024 | |
1025 | |
1026 } | |
1027 | |
1028 function theme_openmindattribute_formatter_field_MPIWG_viewer($vars) { | |
1029 | |
1030 $type = $vars['type']; | |
1031 | |
1032 | |
1033 return theme_render_template(drupal_get_path('module', 'openmindattribute') . "/templates/openmindattribute_MPIWG_viewer.tpl.php", $vars); | |
1034 | |
1035 | |
1036 } | |
1037 | |
1038 | |
1039 function theme_openmindattribute_formatter_fields_default($vars) { | |
1040 | |
1041 | |
1042 | |
1043 return theme_render_template(drupal_get_path('module', 'openmindattribute') . "/templates/openmindattribute_default.tpl.php", $vars); | |
1044 | |
1045 | |
1046 | |
1047 | |
1048 | |
1049 } | |
1050 | |
1051 function theme_openmindattribute_formatter_fields_diva_link($vars) { | |
1052 | |
1053 | |
1054 return theme_render_template(drupal_get_path('module', 'openmindattribute') . "/templates/openmindattribute_diva_link.tpl.php", $vars); | |
1055 | |
1056 } | |
1057 | |
1058 | |
1059 /** | |
1060 * Implements hook_views_api(). | |
1061 */ | |
1062 function openmindattribute_views_api() { | |
1063 return array( | |
1064 'api' => 2, | |
1065 'path' => drupal_get_path('module', 'openmindattribute') . '/views', | |
1066 ); | |
1067 } | |
1068 | |
1069 /** | |
1070 * Implements hook_field_settings_form(). | |
1071 */ | |
1072 function openmindattribute_field_settings_form() { | |
1073 return array(); | |
1074 } | |
1075 | |
1076 /** | |
1077 * Additional callback to adapt the property info of link fields. | |
1078 * | |
1079 * @see entity_metadata_field_entity_property_info(). | |
1080 */ | |
1081 function openmindattribute_field_property_info_callback(&$info, $entity_type, $field, $instance, $field_type) { | |
1082 $property = &$info[$entity_type]['bundles'][$instance['bundle']]['properties'][$field['field_name']]; | |
1083 // Define a data structure so it's possible to deal with both the link title | |
1084 // and URL. | |
1085 $property['getter callback'] = 'entity_metadata_field_verbatim_get'; | |
1086 $property['setter callback'] = 'entity_metadata_field_verbatim_set'; | |
1087 | |
1088 // Auto-create the field item as soon as a property is set. | |
1089 $property['auto creation'] = 'openmindattribute_field_item_create'; | |
1090 | |
1091 $property['property info'] = openmindattribute_field_item_property_info(); | |
1092 $property['property info']['name']['required'] = !$instance['settings']['name']; | |
1093 $property['property info']['ov']['required'] = ($instance['settings']['ov'] == 'required'); | |
1094 if ($instance['settings']['ov'] == 'none') { | |
1095 unset($property['property info']['ov']); | |
1096 } | |
1097 | |
1098 $property['property info']['nov']['required'] = ($instance['settings']['nov'] == 'required'); | |
1099 if ($instance['settings']['nov'] == 'none') { | |
1100 unset($property['property info']['nov']); | |
1101 } | |
1102 unset($property['query callback']); | |
1103 } | |
1104 | |
1105 /** | |
1106 * Callback for creating a new, empty link field item. | |
1107 * | |
1108 * @see link_field_property_info_callback() | |
1109 */ | |
1110 function openmindattribute_field_item_create() { | |
1111 return array('title' => NULL, 'url' => NULL); | |
1112 } | |
1113 | |
1114 /** | |
1115 * Defines info for the properties of the link-field item data structure. | |
1116 */ | |
1117 function openmindattribute_field_item_property_info() { | |
1118 $properties['ov'] = array( | |
1119 'type' => 'text', | |
1120 'label' => t('The OV.'), | |
1121 'setter callback' => 'entity_property_verbatim_set', | |
1122 ); | |
1123 $properties['name'] = array( | |
1124 'type' => 'text', | |
1125 'label' => t('The name of the attribute'), | |
1126 'setter callback' => 'entity_property_verbatim_set', | |
1127 ); | |
1128 | |
1129 $properties['nov'] = array( | |
1130 'type' => 'text', | |
1131 'label' => t('The NOV'), | |
1132 'setter callback' => 'entity_property_verbatim_set', | |
1133 ); | |
1134 return $properties; | |
1135 } | |
1136 | |
1137 #/** | |
1138 # * Implements hook_field_update_instance(). | |
1139 # */ | |
1140 #function openmindattribute_field_update_instance($instance, $prior_instance) { | |
1141 # if (function_exists('i18n_string_update') && $instance['widget']['type'] == 'openmindattribute_field' ) { | |
1142 # $i18n_string_name = "field:{$instance['field_name']}:{$instance['bundle']}:title_value"; | |
1143 # i18n_string_update($i18n_string_name, $instance['settings']['title_value']); | |
1144 # } | |
1145 #} | |
1146 | |
1147 /** | |
1148 * Implements hook_i18n_string_list_TEXTGROUP_alter(). | |
1149 */ | |
1150 #function link_i18n_string_list_field_alter(&$strings, $type = NULL, $object = NULL) { | |
1151 # if ($type != 'field_instance' || !is_array($object) || !isset($object['widget']['type'])) { | |
1152 # return; | |
1153 # } | |
1154 # if ($object['widget']['type'] == 'link_field' && isset($object['settings']['title_value'])) { | |
1155 ## $strings['field'][$object['field_name']][$object['bundle']]['title_value']['string'] = $object['settings']['title_value']; | |
1156 #} | |
1157 #} | |
1158 | |
1159 | |
1160 /** | |
1161 * @file | |
1162 * implementation of Feeds mapping API for link.module. | |
1163 */ | |
1164 | |
1165 /** | |
1166 * Implements hook_feeds_processor_targets_alter(). | |
1167 * | |
1168 * @see FeedsProcessor::getMappingTargets() | |
1169 */ | |
1170 /* | |
1171 function openmindattribute_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_name) { | |
1172 | |
1173 foreach (field_info_instances($entity_type, $bundle_name) as $name => $instance) { | |
1174 $info = field_info_field($name); | |
1175 | |
1176 if ($info['type'] == 'openmindattribute_field') { | |
1177 if (array_key_exists('name', $info['columns'])) { | |
1178 $targets[$name . ':name'] = array( | |
1179 'name' => t('@name: name', array('@name' => $instance['label'])), | |
1180 'callback' => 'openmindattribute_feeds_set_target', | |
1181 'description' => t('The @label field of the entity.', array('@label' => $instance['label'])), | |
1182 'real_target' => $name, | |
1183 ); | |
1184 } | |
1185 if (array_key_exists('ov', $info['columns'])) { | |
1186 $targets[$name . ':ov'] = array( | |
1187 'name' => t('@name: OV', array('@name' => $instance['label'])), | |
1188 'callback' => 'openmindattribute_feeds_set_target', | |
1189 'description' => t('The @label field of the entity.', array('@label' => $instance['label'])), | |
1190 'real_target' => $name, | |
1191 ); | |
1192 } | |
1193 if (array_key_exists('ov', $info['columns'])) { | |
1194 $targets[$name . ':nov'] = array( | |
1195 'name' => t('@name: NOV', array('@name' => $instance['label'])), | |
1196 'callback' => 'openmindattribute_feeds_set_target', | |
1197 'description' => t('The @label field of the entity.', array('@label' => $instance['label'])), | |
1198 'real_target' => $name, | |
1199 ); | |
1200 } | |
1201 } | |
1202 } | |
1203 } | |
1204 */ | |
1205 | |
1206 function openmindattribute_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_name) { | |
1207 | |
1208 foreach (field_info_instances($entity_type, $bundle_name) as $name => $instance) { | |
1209 $info = field_info_field($name); | |
1210 #map the whole attr | |
1211 | |
1212 if ($info['type'] == 'openmindattribute_field') { | |
1213 $targets[$name] = array( | |
1214 'name' => t('@name', array('@name' => $instance['label'])), | |
1215 'callback' => 'openmindattribute_feeds_set_target', | |
1216 'description' => t('The @label field of the entity.', array('@label' => $instance['label'])), | |
1217 'real_target' => $name, | |
1218 ); | |
1219 } | |
1220 | |
1221 | |
1222 } | |
1223 } | |
1224 | |
1225 | |
1226 | |
1227 /** | |
1228 * Callback for mapping. Here is where the actual mapping happens. | |
1229 * | |
1230 * When the callback is invoked, $target contains the name of the field the | |
1231 * user has decided to map to and $value contains the value of the feed item | |
1232 * element the user has picked as a source. | |
1233 */ | |
1234 /* | |
1235 function openmindattribute_feeds_set_target($source, $entity, $target, $value) { | |
1236 if (empty($value)) { | |
1237 return; | |
1238 } | |
1239 | |
1240 // Handle non-multiple value fields. | |
1241 if (!is_array($value)) { | |
1242 $value = array($value); | |
1243 } | |
1244 | |
1245 // Iterate over all values. | |
1246 list($field_name, $column) = explode(':', $target); | |
1247 $info = field_info_field($field_name); | |
1248 | |
1249 $field = isset($entity->$field_name) ? $entity->$field_name : array(); | |
1250 $delta = 0; | |
1251 | |
1252 foreach ($value as $v) { | |
1253 if ($info['cardinality'] == $delta) { | |
1254 break; | |
1255 } | |
1256 | |
1257 if (is_object($v) && ($v instanceof FeedsElement)) { | |
1258 $v = $v->getValue(); | |
1259 } | |
1260 | |
1261 if (is_scalar($v)) { | |
1262 $field['und'][$delta][$column] = $v; | |
1263 $delta++; | |
1264 } | |
1265 } | |
1266 $entity->$field_name = $field; | |
1267 } | |
1268 */ | |
1269 | |
1270 function openmindattribute_feeds_set_target($source, $entity, $target, $value) { | |
1271 | |
1272 if (empty($value)) { | |
1273 return; | |
1274 } | |
1275 | |
1276 // Handle non-multiple value fields. | |
1277 if (!is_array($value)) { | |
1278 $value = array($value); | |
1279 } | |
1280 | |
1281 // Iterate over all values. | |
1282 #list($field_name, $column) = explode(':', $target); | |
1283 | |
1284 $field_name=$target; | |
1285 $info = field_info_field($field_name); | |
1286 | |
1287 $field = isset($entity->$field_name) ? $entity->$field_name : array(); | |
1288 $delta = 0; | |
1289 | |
1290 | |
1291 foreach ($value as $v) { | |
1292 | |
1293 | |
1294 if ($info['cardinality'] == $delta) { | |
1295 break; | |
1296 } | |
1297 | |
1298 if (is_object($v) && ($v instanceof FeedsElement)) { | |
1299 $v = $v->getValue(); | |
1300 } | |
1301 | |
1302 if (is_scalar($v)) { | |
1303 $field['und'][$delta] = $v; | |
1304 $delta++; | |
1305 } | |
1306 | |
1307 if (is_array($v)){ | |
1308 $newVal = array(); | |
1309 $newVal['ov'] = $v['ov']; | |
1310 $newVal['nov'] = $v['nov']; | |
1311 $newVal['name'] = $v['name']; | |
1312 $newVal['romanization'] = $v['romanization']; | |
1313 $field['und'][$delta]= $newVal; | |
1314 $delta++; | |
1315 | |
1316 } | |
1317 } | |
1318 $entity->$field_name = $field; | |
1319 } | |
1320 | |
1321 | |
1322 function openmindattribute_addIDs(){ | |
1323 #adds the author id from openmind to the biographies and umgekehrt | |
1324 $query = new EntityFieldQuery(); | |
1325 | |
1326 $query->entityCondition('entity_type', 'node') | |
1327 ->entityCondition('bundle', 'openmind_entity') | |
1328 ->propertyCondition('status', 1) | |
1329 ->fieldCondition('field_oc', 'tid', '1', '='); #1 is PERSON #TODO should search for PERSON and not the id | |
1330 | |
1331 $result = $query->execute(); | |
1332 | |
1333 | |
1334 if (isset($result['node'])) { | |
1335 $persons_nids = array_keys($result['node']); | |
1336 $persons = entity_load('node', $persons_nids); | |
1337 | |
1338 | |
1339 } | |
1340 | |
1341 #hole mapping bea url -> id | |
1342 | |
1343 $beamapping=array(); | |
1344 $beamappingNodeId=array(); | |
1345 foreach ($persons as $person){ | |
1346 | |
1347 $attrs = $person->field_attribute['und']; | |
1348 | |
1349 | |
1350 $mappedattrs = _openmindattribute_field_remap($attrs); | |
1351 | |
1352 if (isset($mappedattrs['url'])){ | |
1353 | |
1354 $url = $mappedattrs['url']['ov']; | |
1355 | |
1356 $exploded = explode("/", $url); | |
1357 | |
1358 #urls haben die Form http://islamsci.mcgill.ca/rasi/bea/tusi_bea.htm | |
1359 #mich interessiert nur das ende ohne htm | |
1360 | |
1361 dpm($exploded); | |
1362 $ident = $exploded[count($exploded)-1]; | |
1363 dpm($ident); | |
1364 $ident = strtolower(str_replace(".htm", "", $ident)); | |
1365 | |
1366 dpm($ident); | |
1367 $beamapping[$ident]=$person->field_id['und'][0]['value']; | |
1368 //$beamappingNodeId[$ident]=$person->nid; | |
1369 $beamappingNodeId[$ident][]=$person->nid; | |
1370 } | |
1371 | |
1372 } | |
1373 | |
1374 #hole jetzt alle biographien | |
1375 | |
1376 $query = new EntityFieldQuery(); | |
1377 | |
1378 $query->entityCondition('entity_type', 'node') | |
1379 ->entityCondition('bundle', 'biography'); | |
1380 | |
1381 | |
1382 $result = $query->execute(); | |
1383 | |
1384 | |
1385 if (isset($result['node'])) { | |
1386 $bios_nids = array_keys($result['node']); | |
1387 $bios = entity_load('node', $bios_nids); | |
1388 | |
1389 } | |
1390 | |
1391 foreach ($bios as $bio){ | |
1392 $url = strtolower(drupal_get_path_alias("node/" . $bio->nid)); | |
1393 | |
1394 dpm($url); | |
1395 | |
1396 if (isset ($beamapping[$url])){ | |
1397 $authorid = $beamapping[$url]; | |
1398 | |
1399 $bio->field_id['und'][0]['value']=$authorid; | |
1400 | |
1401 | |
1402 | |
1403 | |
1404 node_save($bio); | |
1405 | |
1406 dpm($url . " -->" . $authorid); | |
1407 | |
1408 dpm($bio); | |
1409 | |
1410 | |
1411 foreach ($beamappingNodeId[$url] as $entNid){ | |
1412 //$entNid = $beamappingNodeId[$url]; | |
1413 | |
1414 $ent = entity_load_single("node", $entNid); | |
1415 | |
1416 $ent->field_bio_id['und'][0]['value']=$bio->nid; | |
1417 $ent->field_bio_id_reference['und'][0]['nid']=$bio->nid; | |
1418 dpm($ent); | |
1419 dpm($ent->nid); | |
1420 node_save($ent); | |
1421 }} | |
1422 | |
1423 } | |
1424 | |
1425 | |
1426 } | |
1427 | |
1428 function openmindattribute_addIDbibliographieID(){ | |
1429 #adds the add bibliographie | |
1430 $query = new EntityFieldQuery(); | |
1431 | |
1432 $query->entityCondition('entity_type', 'node') | |
1433 ->entityCondition('bundle', 'openmind_entity') | |
1434 ->propertyCondition('status', 1) | |
1435 ->fieldCondition('field_oc', 'tid', '10', '='); #10 is reference #TODO should search for REFERENCE nd not the id | |
1436 | |
1437 $result = $query->execute(); | |
1438 | |
1439 | |
1440 if (isset($result['node'])) { | |
1441 $reference_nids = array_keys($result['node']); | |
1442 $references = entity_load('node', $reference_nids); | |
1443 | |
1444 } | |
1445 | |
1446 foreach ($references as $reference){ | |
1447 #{King, 1983 #1290} References haben diese Titel | |
1448 # Hole die Nummer | |
1449 | |
1450 $exploded = explode("#", $reference->title); | |
1451 $number = str_replace("}", "", $exploded[1]); | |
1452 | |
1453 | |
1454 #suche jetzt in biblios nach der Nummer "=feld Custom 3" | |
1455 | |
1456 $query = db_select('node', 'n'); | |
1457 $query->addField('n', 'nid'); | |
1458 $query->leftJoin('biblio', 'b', 'n.vid=b.vid'); | |
1459 | |
1460 $query->addField('b', 'biblio_custom3'); | |
1461 $query->condition("b.biblio_custom3", $number); | |
1462 | |
1463 $results=$query->execute(); | |
1464 | |
1465 foreach ($results as $node){ | |
1466 $nid= $node->nid; | |
1467 $ent = entity_load_single("node", $nid); | |
1468 dpm($reference); | |
1469 $reference->field_biblio_reference['und'][0]['nid']=$nid; | |
1470 node_submit($reference); | |
1471 node_save($reference); | |
1472 } | |
1473 | |
1474 | |
1475 } | |
1476 } | |
1477 | |
1478 | |
1479 function _openmindattribute_collection_list($name,&$form){ | |
1480 $query = new EntityFieldQuery(); | |
1481 | |
1482 $query->entityCondition('entity_type', 'node') | |
1483 ->entityCondition('bundle', 'openmind_entity') | |
1484 ->propertyCondition('status', 1) | |
1485 ->fieldCondition('field_oc', 'tid', '8', '='); #8 is COLLECTION #TODO should search for COLLECTION and not the id | |
1486 | |
1487 $result = $query->execute(); | |
1488 | |
1489 $options = array(); | |
1490 | |
1491 if (isset($result['node'])) { | |
1492 $cols_nids = array_keys($result['node']); | |
1493 $cols = entity_load('node', $cols_nids); | |
1494 | |
1495 | |
1496 } | |
1497 | |
1498 | |
1499 $options['']='All'; | |
1500 | |
1501 $titel = array(); | |
1502 | |
1503 foreach ($cols as $col){ | |
1504 $titel[]=$col->title; | |
1505 } | |
1506 | |
1507 sort($titel); | |
1508 | |
1509 foreach($titel as $t){ | |
1510 $options[$t]=$t; | |
1511 } | |
1512 | |
1513 | |
1514 $form[$name]=array( | |
1515 '#type' => 'radios', | |
1516 '#options' => $options, | |
1517 '#default_value' => '' | |
1518 ); | |
1519 } | |
1520 | |
1521 function openmindattribute_form_views_exposed_form_alter(&$form, $form_state, $form_id) { | |
1522 | |
1523 | |
1524 if($form["#id"]=="views-exposed-form-codices-page-codices"){ | |
1525 _openmindattribute_collection_list("title",$form); | |
1526 | |
1527 | |
1528 } elseif ($form["#id"]=="views-exposed-form-codices-page-2"){ | |
1529 | |
1530 _openmindattribute_collection_list("title_1",$form); | |
1531 } | |
1532 | |
1533 } | |
1534 | |
1535 |