diff --git a/bibcite_footnotes.module b/bibcite_footnotes.module index 5f2d31b..bc5d39b 100644 --- a/bibcite_footnotes.module +++ b/bibcite_footnotes.module @@ -216,11 +216,9 @@ function bibcite_footnotes_inline_entity_form_entity_form_alter(&$form, FormStat $form['#save_entity'] = TRUE; } -function bibcite_footnotes_form_node_form_alter($form, FormStateInterface $form_state) { +function bibcite_footnotes_form_node_form_alter(&$form, FormStateInterface &$form_state) { $ief = $form_state->get('inline_entity_form'); if ($ief) { - - $serializer = \Drupal::service('serializer'); // Inline entity storage uses hashes to separate out the field instances. $bibcite_references = []; @@ -246,7 +244,7 @@ function bibcite_footnotes_form_node_form_alter($form, FormStateInterface $form_ $citation_text = trim(strip_tags(render($build))); $citation_hash = md5(implode('', $data)); // Attempt to match up pre-saved entities with the eventual saved ones. - $citation_key = $entity->getOriginalId(); + $citation_key = $entity->id->first()->getValue()['value']; $bibcite_references[] = [$citation_text, $citation_key]; } } @@ -256,7 +254,7 @@ function bibcite_footnotes_form_node_form_alter($form, FormStateInterface $form_ $triggering_element = $form_state->getTriggeringElement(); if (!$triggering_element) { - $form['#attached']['library'][] = 'bibcite_footnotes/replace_citations'; + //$form['#attached']['library'][] = 'bibcite_footnotes/replace_citations'; $form['#attached']['drupalSettings']['bibcite_footnotes']['references'] = $bibcite_references; // $form['#attached']['drupalSettings'][''] } diff --git a/js/plugins/reference_footnotes/dialogs/footnotes.js b/js/plugins/reference_footnotes/dialogs/footnotes.js index 4723972..dd91a43 100644 --- a/js/plugins/reference_footnotes/dialogs/footnotes.js +++ b/js/plugins/reference_footnotes/dialogs/footnotes.js @@ -14,7 +14,7 @@ { id: 'reference', type: 'select', - items: editor.config.referenceFootnotes_list, + items: [[" - None - ", 0]].concat(drupalSettings.bibcite_footnotes.references), label: Drupal.t('Reference Footnote item:'), setup: function (element) { if (isEdit) @@ -65,6 +65,22 @@ this.fakeObj = CKEDITOR.plugins.reference_footnotes.getSelectedFootnote( editor ); this.realObj = editor.restoreRealElement( this.fakeObj ); } + var select = this.parts.contents.$.getElementsByTagName('select'); + var selectBox = select.item(0); + // Remove all but the default 'None' item from teh list. + var i; + for (i = selectBox.options.length - 1 ; i >= 1 ; i--) { + selectBox.remove(i) + } + + // Re-add buttons from the current state of Settings. + drupalSettings.bibcite_footnotes.references.forEach(function(reference) { + var newReference = document.createElement('option'); + newReference.text = reference[0]; + newReference.setAttribute("value", reference[1]); + selectBox.add(newReference); + }); + this.setupContent( this.realObj ); }, onOk : function() { diff --git a/js/replace_citations.js b/js/replace_citations.js index 55830e6..a519f0e 100644 --- a/js/replace_citations.js +++ b/js/replace_citations.js @@ -12,18 +12,17 @@ Drupal.behaviors.bibciteFootnotesReplaceCitations = { attach: function attach(context, settings) { + /* if (CKEDITOR.instances) { for (var instance in CKEDITOR.instances) { - var editor = CKEDITOR.instances[instance]; - var config = editor.config; - if (config.hasOwnProperty('referenceFootnotes_list')) { - config.referenceFootnotes_list = drupalSettings.bibcite_footnotes.references; - var name = editor.name; - editor.destroy(); - CKEDITOR.replace(name, config); - } + var editor = CKEDITOR.instances[instance]; + var config = editor.config; + var name = editor.name; + editor.destroy(); + CKEDITOR.replace(name, config); } } + */ } } })(jQuery, Drupal); diff --git a/src/Plugin/CKEditorPlugin/ReferenceFootnotes.php b/src/Plugin/CKEditorPlugin/ReferenceFootnotes.php index 2b94cc5..069bc9d 100644 --- a/src/Plugin/CKEditorPlugin/ReferenceFootnotes.php +++ b/src/Plugin/CKEditorPlugin/ReferenceFootnotes.php @@ -72,27 +72,6 @@ class ReferenceFootnotes extends CKEditorPluginBase { * {@inheritdoc} */ public function getConfig(Editor $editor) { - $uid = \Drupal::currentUser()->id(); - - $query = \Drupal::service('entity.query'); - - $ref_ids = $query - ->get('bibcite_reference') - ->condition('uid', $uid) - ->execute(); - - $reference_storage = \Drupal::entityTypeManager()->getStorage('bibcite_reference')->loadMultiple($ref_ids); - $view_builder = \Drupal::entityTypeManager()->getViewBuilder('bibcite_reference'); - $options = []; - foreach($reference_storage as $ref_id => $ref_item) { - $build = $view_builder->view($ref_item, 'citation'); - $render = render($build); - $output = trim(strip_tags($render)); - //$options[] = [$output, $ref_id]; - $options[] = [$output, $ref_id]; - } - - return ['referenceFootnotes_list' => $options]; + return []; } - }