From af6f215f014e341e5ca244a383f9920727afbe74 Mon Sep 17 00:00:00 2001 From: Alexander O'Neill Date: Fri, 26 Oct 2018 06:17:06 -0300 Subject: [PATCH] Make free-form notes a textarea. Make notes section labels configurable. --- bibcite_footnotes.info.yml | 2 - bibcite_footnotes.module | 22 +++-- css/reference_footnote.css | 1 - .../reference_footnotes/dialogs/footnotes.js | 2 +- .../Filter/ReferenceFootnotesFilter.php | 86 +++++++++++++++++++ 5 files changed, 102 insertions(+), 11 deletions(-) create mode 100644 src/Plugin/Filter/ReferenceFootnotesFilter.php diff --git a/bibcite_footnotes.info.yml b/bibcite_footnotes.info.yml index 876555f..90b71ae 100644 --- a/bibcite_footnotes.info.yml +++ b/bibcite_footnotes.info.yml @@ -7,5 +7,3 @@ dependencies: - bibcite:bibcite - bibcite:bibcite_entity - footnotes:footnotes - - diff --git a/bibcite_footnotes.module b/bibcite_footnotes.module index 904820d..1bad342 100644 --- a/bibcite_footnotes.module +++ b/bibcite_footnotes.module @@ -5,6 +5,7 @@ * Contains bibcite_footnotes.module. */ +use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Url; use Drupal\Core\Link; @@ -25,17 +26,24 @@ function bibcite_footnotes_help($route_name, RouteMatchInterface $route_match) { } } +/** + * Implementation of hook_preprocess_footnote_list(). + * + * Gatehrs all notes and prints out Notes and References as separate lists. + * + * @param $variables Theme variables. + * + * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException + * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException + */ function bibcite_footnotes_preprocess_footnote_list(&$variables) { - - // Drupal 7 requires we use "render element" which just introduces a wrapper - // around the old array. - // $footnotes = $footnotes['footnotes']; - // loop through the footnotes. + $config = \Drupal::config('filter.format.rich_text_references');//filters.filter_reference_footnotes.settings'); $footnotes = $variables['footnotes']; + $notes = [ '#theme' => 'item_list', '#list_type' => 'ul', - '#title' => 'Notes', + '#title' => $config->get('filters.filter_reference_footnotes.settings.notes_section_label'), '#attributes' => ['class' => 'footnotes'], '#wrapper_attributes' => ['class' => 'container'], ]; @@ -43,7 +51,7 @@ function bibcite_footnotes_preprocess_footnote_list(&$variables) { $references= [ '#theme' => 'item_list', '#list_type' => 'ul', - '#title' => 'References', + '#title' => $config->get('filters.filter_reference_footnotes.settings.references_section_label'), '#attributes' => ['class' => 'footnotes'], '#wrapper_attributes' => ['class' => 'container'], diff --git a/css/reference_footnote.css b/css/reference_footnote.css index 7c212de..2df1272 100644 --- a/css/reference_footnote.css +++ b/css/reference_footnote.css @@ -5,4 +5,3 @@ .footnotes .footnote .footnote-link::after { content: " "; white-space: pre; -} \ No newline at end of file diff --git a/js/plugins/reference_footnotes/dialogs/footnotes.js b/js/plugins/reference_footnotes/dialogs/footnotes.js index 1462b0e..55bf701 100644 --- a/js/plugins/reference_footnotes/dialogs/footnotes.js +++ b/js/plugins/reference_footnotes/dialogs/footnotes.js @@ -23,7 +23,7 @@ }, { id: 'footnote', - type: 'text', + type: 'textarea', label: Drupal.t('Or add free-form footnote text :'), setup: function (element) { if (isEdit) diff --git a/src/Plugin/Filter/ReferenceFootnotesFilter.php b/src/Plugin/Filter/ReferenceFootnotesFilter.php new file mode 100644 index 0000000..7903726 --- /dev/null +++ b/src/Plugin/Filter/ReferenceFootnotesFilter.php @@ -0,0 +1,86 @@ +config = \Drupal::config('reference_footnotes.settings'); + $this->configEditable = \Drupal::configFactory() + ->getEditable('reference_footnotes.settings'); + } + + /** + * Create the settings form for the filter. + * + * @param array $form + * A minimally prepopulated form array. + * @param FormStateInterface $form_state + * The state of the (entire) configuration form. + * + * @return array + * The $form array with additional form elements for the settings of + * this filter. The submitted form values should match $this->settings. + */ + public function settingsForm(array $form, FormStateInterface $form_state) { + $settings['footnotes_collapse'] = [ + '#type' => 'checkbox', + '#title' => t('Collapse reference footnotes with identical content'), + '#default_value' => $this->settings['footnotes_collapse'], + '#description' => t('If two reference footnotes have the exact same content, they will be collapsed into one as if using the same value="" attribute.'), + ]; + $settings['notes_section_label'] = [ + '#type' => 'textfield', + '#title' => t('Notes section label'), + '#default_value' => $this->settings['notes_section_label'], + ]; + $settings['references_section_label'] = [ + '#type' => 'textfield', + '#title' => $this->t('References section label'), + '#description' => $this->t('E.g., "Works Cited" for MLA style.'), + '#default_value' => $this->settings['references_section_label'], + ]; + return $settings; + } + +}