Browse Source

WIP Start work on combined notes and references.

mla_citations_3
Alexander O'Neill 6 years ago
parent
commit
9406e12494
  1. 23
      bibcite_footnotes.module
  2. 13
      js/plugins/reference_footnotes/dialogs/footnotes.js
  3. 9
      js/plugins/reference_footnotes/plugin.js
  4. 8
      src/Plugin/Filter/ReferenceFootnotesFilter.php

23
bibcite_footnotes.module

@ -69,7 +69,7 @@ function bibcite_footnotes_preprocess_footnote_list(&$variables) {
],
];
$build = [];
$reference_entity_id = _bibcite_footnotes_get_reference_entity_id_from_bibcite_footnote($fn['text']);
$reference_entity_id = _bibcite_footnotes_get_reference_entity_id_from_bibcite_footnote($fn['reference']);
$footnote_link_text = $dont_show_backlink_text && $reference_entity_id ? '^' : $fn['value'];
if (!is_array($fn['ref_id'])) {
@ -99,8 +99,21 @@ function bibcite_footnotes_preprocess_footnote_list(&$variables) {
}
if (!empty($fn['text'])) {
$note_build[] = $build + ['#type' => 'markup', '#markup' => ' ' . $fn['text']];
if (!empty($reference_entity_id)) {
$citation_build = $citation_tools->getRenderableReference($reference_entity_id);
$note_build[] = $citation_build;
}
$note_item = [] + $item;
$note_item['#markup'] = render($note_build);
$notes['#items'][] = $note_item;
}
if (!empty($reference_entity_id)) {
$citation_build = $citation_tools->getRenderableReference($reference_entity_id);
$build[] = $citation_build;
$render = render($build);
$item['#markup'] = $render;
@ -108,13 +121,7 @@ function bibcite_footnotes_preprocess_footnote_list(&$variables) {
$references['#items'][] = $item;
}
else {
$build[] = ['#type' => 'markup', '#markup' => ' ' . $fn['text']];
$render = render($build);
$item['#markup'] = $render;
$notes['#items'][] = $item;
}
}
$variables['notes'] = $notes;
@ -149,7 +156,7 @@ function bibcite_footnotes_preprocess_footnote_link(&$variables) {
$class = 'see-footnote';
// Generate the hover text
$citation_tools = new CitationTools();
$citation_entity_id = _bibcite_footnotes_get_reference_entity_id_from_bibcite_footnote($fn['text']);
$citation_entity_id = _bibcite_footnotes_get_reference_entity_id_from_bibcite_footnote($fn['reference']);
$citation_data = $citation_tools->getRenderableReference($citation_entity_id);
// Citation contains a page reference, so construct parenthetical footnote.

13
js/plugins/reference_footnotes/dialogs/footnotes.js

@ -18,7 +18,7 @@
label: Drupal.t('Reference Footnote item:'),
setup: function (element) {
if (isEdit)
this.setValue(element.getText());
this.setValue(element.getAttribute('reference'));
}
},
{
@ -27,10 +27,10 @@
label: Drupal.t('Or add free-form footnote text :'),
setup: function (element) {
if (isEdit) {
var text = element.getText();
if (!text.match(/\[bibcite_reference:(\d*)\]/)) {
this.setValue(text);
}
var text = element.getText();
this.setValue(text);
}
}
},
@ -70,9 +70,8 @@
onOk : function() {
var referenceNote = this.getValueOf('info', 'reference_footnote');
var textNote = this.getValueOf('info', 'footnote');
var value = textNote ? textNote : referenceNote;
var page = this.getValueOf('info', 'page');
CKEDITOR.plugins.reference_footnotes.createFootnote( editor, this.realObj, value, this.getValueOf('info', 'value'), page);
CKEDITOR.plugins.reference_footnotes.createFootnote( editor, this.realObj, textNote, this.getValueOf('info', 'value'), referenceNote, page);
delete this.fakeObj;
delete this.realObj;
}

9
js/plugins/reference_footnotes/plugin.js

@ -29,10 +29,10 @@
init: function( editor )
{
editor.addCommand('createreferencefootnotes', new CKEDITOR.dialogCommand('createreferencefootnotes', {
allowedContent: 'fn[value][page]'
allowedContent: 'fn[value]'
}));
editor.addCommand('editreferencefootnotes', new CKEDITOR.dialogCommand('editreferencefootnotes', {
allowedContent: 'fn[value][page]'
allowedContent: 'fn[value]'
}));
// Drupal Wysiwyg requirement: The first argument to editor.ui.addButton()
@ -94,7 +94,7 @@
})();
CKEDITOR.plugins.reference_footnotes = {
createFootnote: function( editor, origElement, text, value, page) {
createFootnote: function( editor, origElement, text, value, reference, page) {
if (!origElement) {
var realElement = CKEDITOR.dom.element.createFromHtml('<fn></fn>');
}
@ -109,6 +109,9 @@ CKEDITOR.plugins.reference_footnotes = {
if (page && page.length > 0) {
realElement.setAttribute('page', page);
}
if (reference && reference.length > 0) {
realElement.setAttribute('reference', reference);
}
var fakeElement = editor.createFakeElement( realElement , 'cke_reference_footnote', 'hiddenfield', false );
editor.insertElement(fakeElement);

8
src/Plugin/Filter/ReferenceFootnotesFilter.php

@ -163,7 +163,7 @@ class ReferenceFootnotesFilter extends FootnotesFilter {
// (fixes http://drupal.org/node/194558).
$randstr = $this->randstr();
$value = $this->extractAtribute($matches, 'value');
$value = $this->extractAttribute($matches, 'value');
if ($value) {
// A value label was found. If it is numeric, record it in $n so further
@ -191,7 +191,8 @@ class ReferenceFootnotesFilter extends FootnotesFilter {
// attribute.
$value_id = preg_replace('|[^\w\-]|', '', $value);
$page = $this->extractAtribute($matches, 'page');
$page = $this->extractAttribute($matches, 'page');
$reference = $this->extractAttribute($matches, 'reference');
// Create a sanitized version of $text that is suitable for using as HTML
// attribute value. (In particular, as the title attribute to the footnote
@ -211,6 +212,7 @@ class ReferenceFootnotesFilter extends FootnotesFilter {
'text' => $matches[2],
'text_clean' => $text_clean,
'page' => $page,
'reference' => $reference,
'fn_id' => 'footnote' . $value_id . '_' . $randstr,
'ref_id' => 'footnoteref' . $value_id . '_' . $randstr,
];
@ -286,7 +288,7 @@ class ReferenceFootnotesFilter extends FootnotesFilter {
*
* @return string
*/
protected function extractAtribute($matches, $attribute): string {
protected function extractAttribute($matches, $attribute): string {
$value = '';
// Did the pattern match anything in the <fn> tag?
if ($matches[1]) {

Loading…
Cancel
Save