Browse Source

Make free-form notes a textarea. Make notes section labels configurable.

mla_citations
Alexander O'Neill 6 years ago
parent
commit
af6f215f01
  1. 2
      bibcite_footnotes.info.yml
  2. 22
      bibcite_footnotes.module
  3. 1
      css/reference_footnote.css
  4. 2
      js/plugins/reference_footnotes/dialogs/footnotes.js
  5. 86
      src/Plugin/Filter/ReferenceFootnotesFilter.php

2
bibcite_footnotes.info.yml

@ -7,5 +7,3 @@ dependencies:
- bibcite:bibcite - bibcite:bibcite
- bibcite:bibcite_entity - bibcite:bibcite_entity
- footnotes:footnotes - footnotes:footnotes

22
bibcite_footnotes.module

@ -5,6 +5,7 @@
* Contains bibcite_footnotes.module. * Contains bibcite_footnotes.module.
*/ */
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url; use Drupal\Core\Url;
use Drupal\Core\Link; 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) { function bibcite_footnotes_preprocess_footnote_list(&$variables) {
$config = \Drupal::config('filter.format.rich_text_references');//filters.filter_reference_footnotes.settings');
// Drupal 7 requires we use "render element" which just introduces a wrapper
// around the old array.
// $footnotes = $footnotes['footnotes'];
// loop through the footnotes.
$footnotes = $variables['footnotes']; $footnotes = $variables['footnotes'];
$notes = [ $notes = [
'#theme' => 'item_list', '#theme' => 'item_list',
'#list_type' => 'ul', '#list_type' => 'ul',
'#title' => 'Notes', '#title' => $config->get('filters.filter_reference_footnotes.settings.notes_section_label'),
'#attributes' => ['class' => 'footnotes'], '#attributes' => ['class' => 'footnotes'],
'#wrapper_attributes' => ['class' => 'container'], '#wrapper_attributes' => ['class' => 'container'],
]; ];
@ -43,7 +51,7 @@ function bibcite_footnotes_preprocess_footnote_list(&$variables) {
$references= [ $references= [
'#theme' => 'item_list', '#theme' => 'item_list',
'#list_type' => 'ul', '#list_type' => 'ul',
'#title' => 'References', '#title' => $config->get('filters.filter_reference_footnotes.settings.references_section_label'),
'#attributes' => ['class' => 'footnotes'], '#attributes' => ['class' => 'footnotes'],
'#wrapper_attributes' => ['class' => 'container'], '#wrapper_attributes' => ['class' => 'container'],

1
css/reference_footnote.css

@ -5,4 +5,3 @@
.footnotes .footnote .footnote-link::after { .footnotes .footnote .footnote-link::after {
content: " "; content: " ";
white-space: pre; white-space: pre;
}

2
js/plugins/reference_footnotes/dialogs/footnotes.js

@ -23,7 +23,7 @@
}, },
{ {
id: 'footnote', id: 'footnote',
type: 'text', type: 'textarea',
label: Drupal.t('Or add free-form footnote text :'), label: Drupal.t('Or add free-form footnote text :'),
setup: function (element) { setup: function (element) {
if (isEdit) if (isEdit)

86
src/Plugin/Filter/ReferenceFootnotesFilter.php

@ -0,0 +1,86 @@
<?php
namespace Drupal\bibcite_footnotes\Plugin\Filter;
use Drupal\footnotes\Plugin\Filter\FootnotesFilter;
use Drupal\Core\Form\FormStateInterface;
/**
* Provides a base filter for Reference Footnotes filter.
*
* @Filter(
* id = "filter_reference_footnotes",
* module = "bibcite_footnotes",
* title = @Translation("Reference Footnotes filter"),
* description = @Translation("You can insert footnotes directly into texts."),
* type = \Drupal\filter\Plugin\FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
* cache = FALSE,
* settings = {
* "footnotes_collapse" = FALSE,
* "notes_section_label" = "Notes",
* "references_section_label" = "References"
* },
* weight = 0
* )
*/
class ReferenceFootnotesFilter extends FootnotesFilter {
/**
* Object with configuration for reference footnotes.
*
* @var object
*/
protected $config;
/**
* Object with configuration for reference footnotes, where we need editable..
*
* @var object
*/
protected $configEditable;
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, array $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->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;
}
}
Loading…
Cancel
Save