|
|
|
@ -314,3 +314,52 @@ function bibcite_footnotes_get_ckeditor_select_item($entity): array {
|
|
|
|
|
$citation_key = $entity->id->first()->getValue()['value']; |
|
|
|
|
return [$citation_text, $citation_key]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Implementation of hook_preprocess_field(). |
|
|
|
|
* Sor the works cited list by rendered text, which results in author(s) then title. |
|
|
|
|
* |
|
|
|
|
* @param $variables |
|
|
|
|
* @param $hook |
|
|
|
|
*/ |
|
|
|
|
function bibcite_footnotes_preprocess_field(&$variables, $hook) { |
|
|
|
|
$citation_tools = new CitationTools(); |
|
|
|
|
if ($variables['field_name'] == 'field_bibcite_fn_works_cited') { |
|
|
|
|
|
|
|
|
|
foreach($variables['element'] as $index => $element) { |
|
|
|
|
if (is_numeric($index)) { |
|
|
|
|
$renderable = $citation_tools->getRenderableReference($element['#bibcite_reference']); |
|
|
|
|
$items[] = [ |
|
|
|
|
'orig_index' => $index, |
|
|
|
|
'orig_element' => $element, |
|
|
|
|
'rendered' => trim(strip_tags(render($renderable))), |
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
uasort($items, '_bibcite_footnotes_sort_rendered_references'); |
|
|
|
|
$i = 0; |
|
|
|
|
foreach ($items as $item) { |
|
|
|
|
$variables['element'][$i] = $item['orig_element']; |
|
|
|
|
$variables['element']['#items'][$i] = $item['orig_element']; |
|
|
|
|
$variables['items'][$i]['content'] = $item['orig_element']; |
|
|
|
|
$i += 1; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Comparator function for theme field preprocess. |
|
|
|
|
* |
|
|
|
|
* @param $a |
|
|
|
|
* The first renderable element. |
|
|
|
|
* @param $b |
|
|
|
|
* The second renderable element. |
|
|
|
|
* |
|
|
|
|
* @return int |
|
|
|
|
*/ |
|
|
|
|
function _bibcite_footnotes_sort_rendered_references($a, $b) { |
|
|
|
|
if ($a['rendered'] == $b['rendered']) { |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
return strtolower($a['rendered']) < strtolower($b['rendered']) ? -1 : 1; |
|
|
|
|
} |