Browse Source

WIP - get reference select list to automatically update.

ief
Alexander O'Neill 6 years ago
parent
commit
bf9d7bff3f
  1. 8
      bibcite_footnotes.module
  2. 18
      js/plugins/reference_footnotes/dialogs/footnotes.js
  3. 15
      js/replace_citations.js
  4. 23
      src/Plugin/CKEditorPlugin/ReferenceFootnotes.php

8
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']['']
}

18
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() {

15
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);

23
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 [];
}
}

Loading…
Cancel
Save