From 8210b1c200cbfc1ff3419bebf9a803991a4b5ce5 Mon Sep 17 00:00:00 2001 From: Alexander O'Neill Date: Thu, 22 Nov 2018 06:02:30 -0400 Subject: [PATCH] WIP: Got relace of footnotes working, need to force ckeditor drop-down to reload. --- bibcite_footnotes.libraries.yml | 7 +++++++ bibcite_footnotes.module | 14 +++++--------- js/replace_citations.js | 28 ++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 9 deletions(-) create mode 100644 js/replace_citations.js diff --git a/bibcite_footnotes.libraries.yml b/bibcite_footnotes.libraries.yml index cb3a423..a14bf7c 100644 --- a/bibcite_footnotes.libraries.yml +++ b/bibcite_footnotes.libraries.yml @@ -3,6 +3,13 @@ reference_footnote: css: theme: css/reference_footnote.css: {} + dependencies: + - core/jquery + - core/drupalSettings +replace_citations: + version: VERSION + js: + js/replace_citations.js: {} dependencies: - core/jquery - core/drupalSettings \ No newline at end of file diff --git a/bibcite_footnotes.module b/bibcite_footnotes.module index dd0339b..b706d8f 100644 --- a/bibcite_footnotes.module +++ b/bibcite_footnotes.module @@ -238,9 +238,10 @@ function bibcite_footnotes_form_node_form_alter(&$form, FormStateInterface &$for $data = $serializer->normalize($entity, 'csl'); $build = ['#theme' => 'bibcite_citation', '#data' => $data]; $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. - $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; } else { - $data = $bibcite_references; - $form[$triggering_element['#parents'][0]]['widget']['#attached']['drupalSettings']['bibcite_footnotes']['references'] = $data; - //$response = $form_state->getResponse(); - //if (!empty($response)) { - // $response->addCommand(new SettingsCommand ($data, TRUE)); - //} - + $form[$triggering_element['#parents'][0]]['widget']['#attached']['library'][] = 'bibcite_footnotes/replace_citations'; + $form[$triggering_element['#parents'][0]]['widget']['#attached']['drupalSettings']['bibcite_footnotes']['references'] = $bibcite_references; } } } diff --git a/js/replace_citations.js b/js/replace_citations.js new file mode 100644 index 0000000..ae69224 --- /dev/null +++ b/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);