Revision f23ae4e3
Added by Andreas Kohlbecker about 8 years ago
modules/cdm_dataportal/includes/descriptions.inc | ||
---|---|---|
355 | 355 |
} |
356 | 356 |
|
357 | 357 |
|
358 |
/** |
|
359 |
* Compare callback to be used in usort() to sort render arrays produced by compose_description_element(). |
|
360 |
* |
|
361 |
* @param $a |
|
362 |
* @param $b |
|
363 |
*/ |
|
364 |
function compare_description_element_render_arrays($a, $b){ |
|
365 |
if ($a['#value'].$a['#value-suffix'] == $b['#value'].$b['#value-suffix']) { |
|
366 |
return 0; |
|
367 |
} |
|
368 |
return ($a['#value'].$a['#value-suffix'] < $b['#value'].$b['#value-suffix']) ? -1 : 1; |
|
369 |
|
|
370 |
} |
|
371 |
|
|
358 | 372 |
|
359 | 373 |
/** |
360 | 374 |
* @param $render_array |
... | ... | |
371 | 385 |
'#tag' => cdm_feature_block_element_tag_name($feature_block_settings), |
372 | 386 |
|
373 | 387 |
'#attributes' => array( |
374 |
'class' => 'DescriptionElement DescriptionElement-' . $element->class . ' |
|
375 |
' . html_class_attribute_ref($element) |
|
388 |
'class' => array( |
|
389 |
'DescriptionElement', |
|
390 |
'DescriptionElement-' . $element->class, |
|
391 |
html_class_attribute_ref($element) |
|
392 |
) |
|
376 | 393 |
), |
377 | 394 |
|
378 | 395 |
'#value' => '', |
... | ... | |
844 | 861 |
// --- tree |
845 | 862 |
if (is_object($distribution_info_dto->tree)) { |
846 | 863 |
$distribution_tree_render_array = compose_distribution_hierarchy($distribution_info_dto->tree, $feature_block_settings); |
847 |
$dto_out_array[] = drupal_render($distribution_tree_render_array);
|
|
864 |
$dto_out_array[] = $distribution_tree_render_array;
|
|
848 | 865 |
} |
849 | 866 |
|
850 | 867 |
// --- sorted element list |
... | ... | |
857 | 874 |
} |
858 | 875 |
ksort($distributionElements); |
859 | 876 |
$distribution_element_render_array = compose_description_elements_distribution($distributionElements); |
860 |
$dto_out_array[] = drupal_render($distribution_element_render_array);
|
|
877 |
$dto_out_array[] = $distribution_element_render_array;
|
|
861 | 878 |
|
862 | 879 |
} |
863 | 880 |
// |
... | ... | |
948 | 965 |
$out = render_taxon_or_name($element->taxon2, url(path_to_taxon($element->taxon2->uuid))); |
949 | 966 |
} |
950 | 967 |
|
951 |
$annotations_and_sources = handle_annotations_and_sources( |
|
952 |
$element, |
|
953 |
$feature_block_settings, |
|
954 |
$out, // the description element text |
|
955 |
$element->feature->uuid |
|
956 |
); |
|
957 |
|
|
958 |
if(!empty($annotations_and_sources['source_references'])){ |
|
959 |
$out .= ' ' . join(' ', $annotations_and_sources['source_references'] ); |
|
960 |
} |
|
961 |
return '<' . $enclosing_tag . '>' . $out . $annotations_and_sources['foot_note_keys'] . '</' . $enclosing_tag . '>'; |
|
968 |
$render_array = compose_description_element($element, $feature_block_settings, $out, $element->feature->uuid); |
|
962 | 969 |
|
970 |
return $render_array; |
|
963 | 971 |
} |
964 | 972 |
|
965 | 973 |
|
... | ... | |
988 | 996 |
|
989 | 997 |
$out .= drupal_render($render_array); |
990 | 998 |
|
991 |
$annotations_and_sources = handle_annotations_and_sources( |
|
992 |
$element, |
|
993 |
$feature_block_settings, |
|
994 |
$out, // the description element text |
|
995 |
$element->feature->uuid |
|
996 |
); |
|
997 |
|
|
998 |
if(!empty($annotations_and_sources['source_references'])){ |
|
999 |
$out .= ' ' . join(' ', $annotations_and_sources['source_references'] ); |
|
1000 |
} |
|
1001 |
return '<' . $enclosing_tag . '>' . $out . $annotations_and_sources['foot_note_keys'] . '</' . $enclosing_tag . '>'; |
|
1002 |
|
|
999 |
$render_array = compose_description_element($element, $feature_block_settings, $out, $element->feature->uuid); |
|
1003 | 1000 |
|
1001 |
return $render_array; |
|
1004 | 1002 |
} |
1005 | 1003 |
|
1006 | 1004 |
/** |
... | ... | |
1042 | 1040 |
|
1043 | 1041 |
$out = '<span class="' . html_class_attribute_ref($element) . '">' . implode(', ', $state_data_strings) . '</span>'; |
1044 | 1042 |
|
1045 |
$feature_block_settings = get_feature_block_settings($element->feature->uuid); |
|
1046 |
$annotations_and_sources = handle_annotations_and_sources( |
|
1047 |
$element, |
|
1048 |
$feature_block_settings, |
|
1049 |
$out, // The description element text. |
|
1050 |
$element->feature->uuid |
|
1051 |
); |
|
1043 |
$render_array = compose_description_element($element, $feature_block_settings, $out, $element->feature->uuid); |
|
1052 | 1044 |
|
1053 |
if (!empty($annotations_and_sources['source_references'])) { |
|
1054 |
$out .= ' ' . implode(' ', $annotations_and_sources['source_references']); |
|
1055 |
} |
|
1056 |
return '<' . $enclosing_tag . '>' . $out . $annotations_and_sources['foot_note_keys'] . '</' . $enclosing_tag . '>'; |
|
1045 |
return $render_array; |
|
1057 | 1046 |
} |
1058 | 1047 |
|
1059 | 1048 |
|
... | ... | |
1162 | 1151 |
$out = $element->modifyingText_L10n . ' ' . $out; |
1163 | 1152 |
} |
1164 | 1153 |
|
1165 |
$feature_block_settings = get_feature_block_settings($element->feature->uuid); |
|
1166 |
$annotations_and_sources = handle_annotations_and_sources( |
|
1167 |
$element, |
|
1168 |
$feature_block_settings, |
|
1169 |
$out, // the description element text |
|
1170 |
$element->feature->uuid |
|
1171 |
); |
|
1172 |
|
|
1173 |
if (!empty($annotations_and_sources['source_references'])) { |
|
1174 |
$out .= ' ' . implode(' ', $annotations_and_sources['source_references']); |
|
1175 |
} |
|
1176 |
return $out . $annotations_and_sources['foot_note_keys']; |
|
1154 |
$render_array = compose_description_element($element, $feature_block_settings, $out, $element->feature->uuid); |
|
1177 | 1155 |
|
1156 |
return $render_array; |
|
1178 | 1157 |
} |
1179 | 1158 |
|
1180 | 1159 |
|
... | ... | |
1182 | 1161 |
* Creates a render array for string representations of description elements for the given feature. |
1183 | 1162 |
* |
1184 | 1163 |
* @param array $elements |
1185 |
* An array of strings. Can be plaintext or markup. |
|
1164 |
* An list of render arrays. Which are usually are produced by the compose_description_element() |
|
1165 |
* function. The render arrays should be of #type=html_tag, so that they can understand the #attribute property. |
|
1186 | 1166 |
* @param $feature : |
1187 | 1167 |
* The feature to which the elements given in $elements are belonging to. |
1188 | 1168 |
* @param string $glue : |
... | ... | |
1200 | 1180 |
$feature_block_settings = get_feature_block_settings($feature->uuid); |
1201 | 1181 |
$enclosing_tag = $feature_block_settings['as_list']; |
1202 | 1182 |
|
1203 |
$out = '<' . $enclosing_tag . ' class="feature-block-elements" id="' . $feature->representation_L10n . '">'; |
|
1183 |
if ($sort) { // TODO remove parameter and replace by $feature_block_settings['sort_elements'] |
|
1184 |
usort($elements, 'compare_description_element_render_arrays'); |
|
1185 |
} |
|
1204 | 1186 |
|
1205 |
if ($sort) { |
|
1206 |
sort($elements); |
|
1187 |
$is_first = true; |
|
1188 |
foreach($elements as &$element_render_array){ |
|
1189 |
if(!is_array($element_render_array)){ |
|
1190 |
$element_render_array = markup_to_render_array($element_render_array); |
|
1191 |
} |
|
1192 |
$element_render_array['#attributes']['class'][] = "feature-block-element"; |
|
1193 |
|
|
1194 |
// add the glue! |
|
1195 |
if(!$is_first) { |
|
1196 |
if (isset($element_render_array['#value'])) { |
|
1197 |
$element_render_array['#value'] = $glue . $element_render_array['#value']; |
|
1198 |
} elseif (isset($element_render_array['#markup'])) { |
|
1199 |
$element_render_array['#markup'] = $glue . $element_render_array['#markup']; |
|
1200 |
} |
|
1201 |
} |
|
1202 |
$is_first = false; |
|
1207 | 1203 |
} |
1208 | 1204 |
|
1209 |
//TODO it would be nice if any element would get "feature-block-element" as additional class attribute |
|
1210 |
// this will become possible once all $elements are real Drupal render arrays |
|
1211 |
$out .= join($glue, $elements) ; |
|
1205 |
$render_array['elements']['children'] = $elements; |
|
1212 | 1206 |
|
1213 |
$out .= '</' . $enclosing_tag . '>'; |
|
1214 |
return markup_to_render_array($out); |
|
1207 |
$render_array['elements']['#prefix'] = '<' . $enclosing_tag . ' class="feature-block-elements" id="' . $feature->representation_L10n . '">'; |
|
1208 |
$render_array['elements']['#suffix'] = '</' . $enclosing_tag . '>'; |
|
1209 |
|
|
1210 |
return $render_array; |
|
1215 | 1211 |
} |
1216 | 1212 |
|
1217 | 1213 |
|
... | ... | |
1325 | 1321 |
* Features handled here: |
1326 | 1322 |
* all except DISTRIBUTION, COMMON_NAME, USES, IMAGES, |
1327 | 1323 |
* |
1328 |
* |
|
1329 | 1324 |
* TODO provide api_hook as extension point for this? |
1330 | 1325 |
*/ |
1331 |
$feature_block_settings = get_feature_block_settings($descriptionElement->feature->uuid);
|
|
1326 |
$feature_block_settings = get_feature_block_settings($descriptionElement->feature->uuid); |
|
1332 | 1327 |
switch ($descriptionElement->class) { |
1333 |
case 'TextData': |
|
1334 |
$text_data_render_array = compose_description_element_text_data($descriptionElement, $descriptionElement->feature->uuid, $feature_block_settings); |
|
1335 |
$feature_block_has_content = $feature_block_has_content || !empty($text_data_render_array['#value']); |
|
1336 |
$elements_out_array[] = drupal_render($text_data_render_array); |
|
1337 |
break; |
|
1338 |
case 'CategoricalData': |
|
1339 |
$feature_block_has_content = true; |
|
1340 |
$elements_out_array[] = compose_description_element_categorical_data($descriptionElement, $feature_block_settings); |
|
1341 |
break; |
|
1342 |
case 'QuantitativeData': |
|
1343 |
$feature_block_has_content = true; |
|
1344 |
$elements_out_array[] = compose_description_element_quantitative_data($descriptionElement, $feature_block_settings); |
|
1345 |
break; |
|
1346 |
case 'IndividualsAssociation': |
|
1347 |
$feature_block_has_content = true; |
|
1348 |
$elements_out_array[] = compose_description_element_individuals_association($descriptionElement, $feature_block_settings); |
|
1349 |
break; |
|
1350 |
case 'TaxonInteraction': |
|
1351 |
$feature_block_has_content = true; |
|
1352 |
$elements_out_array[] = compose_description_element_taxon_interaction($descriptionElement, $feature_block_settings); |
|
1353 |
break; |
|
1354 |
case 'Uses': |
|
1355 |
/* IGNORE Uses classes, these are handled completely in theme_cdm_UseDescription */ |
|
1356 |
break; |
|
1357 |
default: |
|
1358 |
$feature_block_has_content = true; |
|
1359 |
$elements_out_array[] = '<li>No method for rendering unknown description class: ' . $descriptionElement->class . '</li>'; |
|
1360 |
} |
|
1361 |
} // --- END loop over normal description element arrays |
|
1328 |
case 'TextData': |
|
1329 |
$elements_out_array[] = compose_description_element_text_data($descriptionElement, $descriptionElement->feature->uuid, $feature_block_settings); |
|
1330 |
break; |
|
1331 |
case 'CategoricalData': |
|
1332 |
$elements_out_array[] = compose_description_element_categorical_data($descriptionElement, $feature_block_settings); |
|
1333 |
break; |
|
1334 |
case 'QuantitativeData': |
|
1335 |
$elements_out_array[] = compose_description_element_quantitative_data($descriptionElement, $feature_block_settings); |
|
1336 |
break; |
|
1337 |
case 'IndividualsAssociation': |
|
1338 |
$elements_out_array[] = compose_description_element_individuals_association($descriptionElement, $feature_block_settings); |
|
1339 |
break; |
|
1340 |
case 'TaxonInteraction': |
|
1341 |
$elements_out_array[] = compose_description_element_taxon_interaction($descriptionElement, $feature_block_settings); |
|
1342 |
break; |
|
1343 |
case 'Uses': |
|
1344 |
/* IGNORE Uses classes, these are handled completely in theme_cdm_UseDescription */ |
|
1345 |
break; |
|
1346 |
default: |
|
1347 |
$feature_block_has_content = true; |
|
1348 |
$elements_out_array[] = markup_to_render_array('<li>No method for rendering unknown description class: ' . $descriptionElement->class . '</li>'); |
|
1349 |
} |
|
1350 |
$elements_out_array_last_item = $elements_out_array[count($elements_out_array) - 1]; |
|
1351 |
// considering not empty as long as the last item added is a render array |
|
1352 |
$feature_block_has_content = $feature_block_has_content || !empty($elements_out_array_last_item['#type']); |
|
1353 |
} |
|
1362 | 1354 |
|
1363 | 1355 |
// If feature = CITATION sort the list of sources. |
1364 | 1356 |
// This is ONLY for FLORA MALESIANA and FLORE d'AFRIQUE CENTRALE. |
... | ... | |
1417 | 1409 |
} |
1418 | 1410 |
|
1419 | 1411 |
if(isset($common_names[$language_area_key][$element->name])) { |
1420 |
// same name already exists for language and areae combination, se we merge the description elements
|
|
1412 |
// same name already exists for language and area combination, se we merge the description elements |
|
1421 | 1413 |
cdm_merge_description_elements($common_names[$language_area_key][$element->name], $element); |
1422 | 1414 |
} else{ |
1423 | 1415 |
// otherwise add as new entry |
... | ... | |
1460 | 1452 |
$common_name_feature_elements_render_array = compose_feature_block_elements( |
1461 | 1453 |
$common_name_feature_elements, $feature, '; ', FALSE |
1462 | 1454 |
); |
1463 |
$common_name_out .= $common_name_feature_elements_render_array['#markup'];
|
|
1455 |
$common_name_out .= drupal_render($common_name_feature_elements_render_array); // FIXME should this be a render array instead?
|
|
1464 | 1456 |
|
1465 | 1457 |
} |
1466 | 1458 |
|
... | ... | |
1483 | 1475 |
$footnotes .= theme('cdm_footnotes', array('footnoteListKey' => $footnote_key_suggestion)); // FIXME is this needed at all? |
1484 | 1476 |
$footnotes .= theme('cdm_annotation_footnotes', array('footnoteListKey' => $footnote_key_suggestion)); |
1485 | 1477 |
|
1486 |
return markup_to_render_array( |
|
1478 |
return markup_to_render_array( // FIXME markup_to_render_array should no longer be needed
|
|
1487 | 1479 |
'<div class="common_names_as_common_names">' . $common_name_out . '</div>' |
1488 |
.'<div class="common_names_as_text_data">' . $common_name_out_text_data['#markup'] . '</div>'
|
|
1480 |
.'<div class="common_names_as_text_data">' . drupal_render($common_name_out_text_data) . '</div>'
|
|
1489 | 1481 |
.$footnotes, |
1490 | 1482 |
$weight |
1491 | 1483 |
); |
Also available in: Unified diff
harmonizing compose_description_element_* functions