Browse Source

WIP: Got relace of footnotes working, need to force ckeditor drop-down to reload.

ief
Alexander O'Neill 6 years ago
parent
commit
8210b1c200
  1. 7
      bibcite_footnotes.libraries.yml
  2. 14
      bibcite_footnotes.module
  3. 28
      js/replace_citations.js

7
bibcite_footnotes.libraries.yml

@ -6,3 +6,10 @@ reference_footnote:
dependencies: dependencies:
- core/jquery - core/jquery
- core/drupalSettings - core/drupalSettings
replace_citations:
version: VERSION
js:
js/replace_citations.js: {}
dependencies:
- core/jquery
- core/drupalSettings

14
bibcite_footnotes.module

@ -238,9 +238,10 @@ function bibcite_footnotes_form_node_form_alter(&$form, FormStateInterface &$for
$data = $serializer->normalize($entity, 'csl'); $data = $serializer->normalize($entity, 'csl');
$build = ['#theme' => 'bibcite_citation', '#data' => $data]; $build = ['#theme' => 'bibcite_citation', '#data' => $data];
$citation_text = trim(strip_tags(render($build))); $citation_text = trim(strip_tags(render($build)));
$citation_hash = md5(implode($data)); $citation_hash = md5(implode('', $data));
// Attempt to match up pre-saved entities with the eventual saved ones. // Attempt to match up pre-saved entities with the eventual saved ones.
$bibcite_references[$field_name][] = ['hash' => $citation_hash, 'citation' => $citation_text]; $citation_key = !empty($entity->getOriginalId()) ? $entity->getOriginalId() : $citation_hash;
$bibcite_references[] = [$citation_text, $citation_key];
} }
} }
} }
@ -253,13 +254,8 @@ function bibcite_footnotes_form_node_form_alter(&$form, FormStateInterface &$for
$form['#attached']['drupalSettings']['bibcite_footnotes']['references'] = $bibcite_references; $form['#attached']['drupalSettings']['bibcite_footnotes']['references'] = $bibcite_references;
} }
else { else {
$data = $bibcite_references; $form[$triggering_element['#parents'][0]]['widget']['#attached']['library'][] = 'bibcite_footnotes/replace_citations';
$form[$triggering_element['#parents'][0]]['widget']['#attached']['drupalSettings']['bibcite_footnotes']['references'] = $data; $form[$triggering_element['#parents'][0]]['widget']['#attached']['drupalSettings']['bibcite_footnotes']['references'] = $bibcite_references;
//$response = $form_state->getResponse();
//if (!empty($response)) {
// $response->addCommand(new SettingsCommand ($data, TRUE));
//}
} }
} }
} }

28
js/replace_citations.js

@ -0,0 +1,28 @@
/**
* @file
* Provides JavaScript additions to entity embed dialog.
*
* This file provides popup windows for previewing embedded entities from the
* embed dialog.
*/
(function ($, Drupal) {
"use strict";
Drupal.behaviors.bibciteFootnotesReplaceCitations = {
attach: function attach(context, settings) {
var formats = drupalSettings.editor.formats;
if (formats) {
for (var key in formats) {
var format = drupalSettings.editor.formats[key];
if (format.editor == "ckeditor") {
format.editorSettings.referenceFootnotes_list = drupalSettings.bibcite_footnotes.references;
}
}
}
}
}
})(jQuery, Drupal);
Loading…
Cancel
Save