From c094983d60954f19b596ee1afb2474da8feee87d Mon Sep 17 00:00:00 2001 From: Alexander O'Neill Date: Wed, 17 Oct 2018 15:23:10 -0300 Subject: [PATCH] Issue #3007407 by alxp: Add support for free-form text notes --- LICENSE.txt => LICENSE | 2 +- README.md | 8 +- bibcite_footnotes.info.yml | 8 +- bibcite_footnotes.libraries.yml | 5 + bibcite_footnotes.module | 110 +++++++++++++++++- css/reference_footnote.css | 8 ++ js/plugins/reference_footnotes/.DS_Store | Bin 0 -> 6148 bytes .../reference_footnotes/dialogs/footnotes.js | 40 ++++--- .../reference_footnotes/images/fn_icon2.png | Bin 262 -> 0 bytes .../reference_footnotes/images/fn_icon3.png | Bin 0 -> 1136 bytes js/plugins/reference_footnotes/plugin.js | 36 ++++-- templates/footnote-list.html.twig | 21 ++++ 12 files changed, 209 insertions(+), 29 deletions(-) rename LICENSE.txt => LICENSE (99%) create mode 100644 bibcite_footnotes.libraries.yml create mode 100644 css/reference_footnote.css create mode 100644 js/plugins/reference_footnotes/.DS_Store delete mode 100644 js/plugins/reference_footnotes/images/fn_icon2.png create mode 100644 js/plugins/reference_footnotes/images/fn_icon3.png create mode 100644 templates/footnote-list.html.twig diff --git a/LICENSE.txt b/LICENSE similarity index 99% rename from LICENSE.txt rename to LICENSE index 94a9ed0..20d40b6 100644 --- a/LICENSE.txt +++ b/LICENSE @@ -671,4 +671,4 @@ into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read -. +. \ No newline at end of file diff --git a/README.md b/README.md index 776efe4..c195b82 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,13 @@ Installation ------------ Install and set up the Footnotes module as per its installation instructions, including -enabling and configuring the Footnotes text filter. +enabling and configuring the Footnotes text filter. If the 'Allowed HTML tags' filter is enabled +you will need to add the following HTML tags for the reference footnotes to display properly.: + +```html +
    +
    1. +``` Configuration ------------- diff --git a/bibcite_footnotes.info.yml b/bibcite_footnotes.info.yml index a8880af..3b3d9f9 100644 --- a/bibcite_footnotes.info.yml +++ b/bibcite_footnotes.info.yml @@ -1,9 +1,15 @@ name: 'BibCite Footnotes' type: module description: 'Inline footnote links for BibCite References' -core: 8.x +# core: 8.x package: 'Bibliography & Citation' dependencies: - bibcite:bibcite - bibcite:bibcite_entity - footnotes:footnotes + +# Information added by Drupal.org packaging script on 2018-07-30 +version: '8.x-1.0-alpha5' +core: '8.x' +project: 'bibcite_footnotes' +datestamp: 1532941092 diff --git a/bibcite_footnotes.libraries.yml b/bibcite_footnotes.libraries.yml new file mode 100644 index 0000000..66a8c36 --- /dev/null +++ b/bibcite_footnotes.libraries.yml @@ -0,0 +1,5 @@ +reference_footnote: + version: VERSION + css: + theme: + css/reference_footnote.css: {} diff --git a/bibcite_footnotes.module b/bibcite_footnotes.module index cc2dd60..904820d 100644 --- a/bibcite_footnotes.module +++ b/bibcite_footnotes.module @@ -6,6 +6,8 @@ */ use Drupal\Core\Routing\RouteMatchInterface; +use Drupal\Core\Url; +use Drupal\Core\Link; /** * Implements hook_help(). @@ -23,6 +25,96 @@ function bibcite_footnotes_help($route_name, RouteMatchInterface $route_match) { } } +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. + $footnotes = $variables['footnotes']; + $notes = [ + '#theme' => 'item_list', + '#list_type' => 'ul', + '#title' => 'Notes', + '#attributes' => ['class' => 'footnotes'], + '#wrapper_attributes' => ['class' => 'container'], + ]; + + $references= [ + '#theme' => 'item_list', + '#list_type' => 'ul', + '#title' => 'References', + '#attributes' => ['class' => 'footnotes'], + '#wrapper_attributes' => ['class' => 'container'], + + ]; + $references['#attached']['library'][] = 'bibcite_footnotes/reference_footnote'; + + $serializer = \Drupal::service('serializer'); + + foreach ($footnotes as $fn) { + $item = [ + '#id' => $fn['fn_id'], + '#wrapper_attributes' => [ + 'class' => ['footnote'], + ], + ]; + $build = []; + if (!is_array($fn['ref_id'])) { + // Output normal footnote. + + + $url = Url::fromUserInput('#' . $fn['ref_id'], ['attributes' => ['id' => $fn['fn_id'], 'class' => 'footnote-link']]); + $link = Link::fromTextAndUrl($fn['value'], $url)->toRenderable(); + $build[] = $link; + } + else { + // Output footnote that has more than one reference to it in the body. + // The only difference is to insert backlinks to all references. + // Helper: we need to enumerate a, b, c... + $abc = str_split("abcdefghijklmnopqrstuvwxyz"); + $i = 0; + + $url = Url::fromUserInput('#' . $fn['ref_id'][0], ['attributes' => ['id' => $fn['fn_id'], 'class' => 'footnote-link']]); + $build[] = Link::fromTextAndUrl($fn['value'], $url)->toRenderable(); + + foreach ($fn['ref_id'] as $ref) { + $url = Url::fromUserInput( '#' . $ref, ['attributes' => ['id' => $fn['fn_id'], 'class' => 'footnote-multi']]); + $build[] = Link::fromTextAndUrl($abc[$i], $url)->toRenderable(); + + $i++; + } + + } + + preg_match('/\[bibcite_reference:(\d*)\]/', $fn['text'], $matches); + $reference_entity_id = $matches[1]; + if (!empty($reference_entity_id)) { + $reference_storage = \Drupal::entityTypeManager() + ->getStorage('bibcite_reference') + ->load($reference_entity_id); + $data = $serializer->normalize($reference_storage, 'csl'); + $build[] = ['#theme' => 'bibcite_citation', '#data' => $data]; + $render = render($build); + $item['#markup'] = $render; + $references['#items'][] = $item; + + } + else { + $build[] = ['#type' => 'markup', '#markup' => ' ' . $fn['text']]; + $render = render($build); + $item['#markup'] = $render; + + $notes['#items'][] = $item; + } + } + + $variables['notes'] = $notes; + + $variables['references'] = $references; + +} + /** * Implements hook_theme(). */ @@ -35,12 +127,28 @@ function bibcite_footnotes_theme() { } function bibcite_footnotes_theme_registry_alter(&$theme_registry) { - $theme_registry['footnote_list']['function'] = 'bibcite_footnotes_theme_footnote_list'; + unset($theme_registry['footnote_list']['function']); +// $theme_registry['footnote_list']['function'] = 'bibcite_footnotes_theme_footnote_list'; + $theme_registry['footnote_list']['path'] = drupal_get_path('module', 'bibcite_footnotes') . '/templates'; + $theme_registry['footnote_list']['template'] = 'footnote-list'; + $theme_registry['footnote_list']['variables']['notes'] = []; + $theme_registry['footnote_list']['variables']['references'] = []; + $theme_registry['footnote_list']['variables']['footnotes'] = []; } function bibcite_footnotes_theme_footnote_list($footnotes) { // @todo: change this ugly array for arguments in the function. $footnotes = $footnotes['footnotes']['#footnotes']; + + $notes = [ + '#theme' => 'item_list', + '#list_type' => 'ul', + '#title' => 'Notes', + '#attributes' => ['class' => ''], + '#wrapper_attributes' => ['class' => 'container'], + ]; + +// return drupal_render($content); $str = '
        '; // Drupal 7 requires we use "render element" which just introduces a wrapper // around the old array. diff --git a/css/reference_footnote.css b/css/reference_footnote.css new file mode 100644 index 0000000..7c212de --- /dev/null +++ b/css/reference_footnote.css @@ -0,0 +1,8 @@ + +.footnotes .footnote .footnote-link { + float: left; +} +.footnotes .footnote .footnote-link::after { + content: " "; + white-space: pre; +} \ No newline at end of file diff --git a/js/plugins/reference_footnotes/.DS_Store b/js/plugins/reference_footnotes/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..53df026e31f0fdade33041da4db1624e2fedcef9 GIT binary patch literal 6148 zcmeHK%}(1u5S|Tz+C)OG)B}}zScwCd9D>>q^=75OsZtR}aNsAkWkW0(8`%yyM3JmM z01wb!`|}!z_91u??#%3NkfOk`RY5b->^GjBnYBM#J6-?~-9fkp-~fPyN?5aTctB{L zbVh2%Lnu^@2#R1>oCir3%tW)}e`J8(-2%jL20om^^!vLF&Xc$(Tdf;Wo2$<+ys+%W zhTT|d*hgMJ8+xT*4vMay_nbFg97chk@5f=;-;L7EB)W*wPx(i`jPe5t-p#TE1GMc2 zdvP@EIj=rsY3avll&gBW#^HXPhS{*24bres@us-4xBaq@b*vTl8dHQ^ zczK#+=_&drIg?mMW`G%B2A(JbW;?SQPxSuzwwVED;O{X&`-4O!bPZM-)z*On{XWus zosa}=I!h2rgRa3!BhH`*orzG4QLfoH{lsBd^1U3?_dTW21QdaXqLj7marmB#xN jG*m0bSZc+~s7lZ;$v|`sRvOWR!ao9v1|FD!f6Blei&J8+ literal 0 HcmV?d00001 diff --git a/js/plugins/reference_footnotes/dialogs/footnotes.js b/js/plugins/reference_footnotes/dialogs/footnotes.js index ae525da..1462b0e 100644 --- a/js/plugins/reference_footnotes/dialogs/footnotes.js +++ b/js/plugins/reference_footnotes/dialogs/footnotes.js @@ -11,22 +11,31 @@ title: Drupal.t('Add a reference footnote'), elements: [ - { - id: 'reference_footnote', - type: 'select', - items: editor.config.referenceFootnotes_list, - label: Drupal.t('Reference Footnote item:'), - setup: function (element) { - if (isEdit) - this.setValue(element.getText()); - } - }, + { + id: 'reference_footnote', + type: 'select', + items: editor.config.referenceFootnotes_list, + label: Drupal.t('Reference Footnote item:'), + setup: function (element) { + if (isEdit) + this.setValue(element.getText()); + } + }, + { + id: 'footnote', + type: 'text', + label: Drupal.t('Or add free-form footnote text :'), + setup: function (element) { + if (isEdit) + this.setValue(element.getText()); + } + }, { id: 'value', type: 'text', label: Drupal.t('Value :'), labelLayout: 'horizontal', - style: 'float:left;width:100px;', + style: 'float:left;width:200px;', setup: function (element) { if (isEdit) this.setValue(element.getAttribute('value')); @@ -43,17 +52,20 @@ this.setupContent( this.realObj ); }, onOk : function() { - CKEDITOR.plugins.reference_footnotes.createFootnote( editor, this.realObj, this.getValueOf('info', 'reference_footnote'), this.getValueOf('info', 'value')); + var referenceNote = this.getValueOf('info', 'reference_footnote'); + var textNote = this.getValueOf('info', 'footnote'); + var value = textNote ? textNote : referenceNote; + CKEDITOR.plugins.reference_footnotes.createFootnote( editor, this.realObj, value, this.getValueOf('info', 'value')); delete this.fakeObj; delete this.realObj; } } } - CKEDITOR.dialog.add( 'createfootnotes', function( editor ) { + CKEDITOR.dialog.add( 'createreferencefootnotes', function( editor ) { return referenceFootnotesDialog( editor ); }); - CKEDITOR.dialog.add( 'editfootnotes', function( editor ) { + CKEDITOR.dialog.add( 'editreferencefootnotes', function( editor ) { return referenceFootnotesDialog( editor, 1 ); }); })(); \ No newline at end of file diff --git a/js/plugins/reference_footnotes/images/fn_icon2.png b/js/plugins/reference_footnotes/images/fn_icon2.png deleted file mode 100644 index 6a3f89668ca36c6ccc9018d05f5531639ec52935..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 262 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|*pj^6T^Rm@ z;DWu&Cj&(|3p^r=85p>QL70(Y)*K0-AbW|YuPgg44t7ya)u6vGSb#!po-U3d7N?UF z76=$537eGP3p;w?z=Z=qP*t>ET-lB}Vu92@V*>*N1x>w_goFUQo!4I*>h&7f&XCcm zscAEKXe2q)to)wY)jO59%Zs1qmcDpp$kR~CeD?iqNePKH3*rvvGw^Nr`Xp}sXC59N xrWDBnpt0u+5*K+{9T4huIm&QYLqdgtVU>;H!j(JY9spg$;OXk;vd$@?2>_&fSZn|Q diff --git a/js/plugins/reference_footnotes/images/fn_icon3.png b/js/plugins/reference_footnotes/images/fn_icon3.png new file mode 100644 index 0000000000000000000000000000000000000000..98fecb98b3cf42a2f96eb29611d8a042f0e0cbb1 GIT binary patch literal 1136 zcmV-$1dscPP) zaB^>EX>4U6ba`-PAZ2)IW&i+q+U-_NlJh7G-Rl%{1SA21<6r|-bAvhlJP1iA>BN(C zdNGU7R1B8&`<}p|_Rrs){=y|}j(o5bbBqp`&pu1RBDvFbn%VhzUk~oQxRKN4g+Qd3 z_4F9q(l3yQF9Y*SzTL{n_T?unM`zE=p^nIc#nMa5k;+NV>zVShEB>mS^;4TJF3R`M z-T+1o5UP+gWp%j65k--KCM`oY?@@+?u@=o!k{)A6m*pLJm(?A1t}MCULP0Jrg?NY2 zl5=>B-9+e)wR7Z~7g3$L>+1@;-fQZ;ovJH70;x!=sBNJZOhF`$i=ExWc zCGG&dg3S$MC(bNDwzKETg*&%7@4O>LFHH=y$Syi%NlmislN3J&cQMdV2^@*;U`-*G zOD;U)<{5A2gvgblDGX-}i*JJ-34by!j(Q)h%k0txE951k0g=XFZrq^-LbxwX!^C$E zy6PKuMXZ9sFkwz8u(<8yVhjA$TRM4G=mqD=o!XtPE(d@Ju>+DpM|*aWHE?8SBE}3H z6Zk2}T-3`31~>$%OdZ@Pc7jQg5gRtfQ&)nV#5h_&M9`=PYOqm2miGbuV?LpWO3>gb zgb;&;6mlq0qmLoRXmOlT#nik7i)NNATS=OH3MnQ_DdkkMWW^B{a?D0K<(x}F&;r*5 z)&&}+Y_jR*x3I;{wzTD~>}a3e?_rO-?Pm^)^T7i)ttKlSX3HHgj5E_fU#VQ>b<#4{MT!2lXs z24^m@_cE9poVhI66hXimhe1x|!5A3yjU{xxaQDUBA#W7?TfE6L=4ep&8_dz5ZZY?r zw+F1%GQTJ~2^za_VCuBvV1q(SMN%2xq#w`pse@xj-Pf^@tySN|%{9*IHS4~Ysn}Bi zh9@KX$ok5d9$G)K>Icg7G{$4=ry=NtgkEw*Zv{TcnqId)40Q+gVNLfu-p=&w#rOG` zN_r)iS6J54=(Nr4QR5M}HjspB>>pV#XhWe*w#jM%>4IKCJ)%00v@9 zM??Vs0RI60puMM)00009a7bBm000XU000XU0RWnu7ytkO2XskIMF-*v5DpzGqqx`C z0001kNkl0VZ6UvBeI~&?Pn|DA6+tXbAwyRZD!ROv^w30000 0 ) realElement.setAttribute('value',value); - var fakeElement = editor.createFakeElement( realElement , 'cke_footnote', 'hiddenfield', false ); + var fakeElement = editor.createFakeElement( realElement , 'cke_reference_footnote', 'hiddenfield', false ); editor.insertElement(fakeElement); }, diff --git a/templates/footnote-list.html.twig b/templates/footnote-list.html.twig new file mode 100644 index 0000000..288c64e --- /dev/null +++ b/templates/footnote-list.html.twig @@ -0,0 +1,21 @@ +{# +/** + * @file footnote-list.html.twig + * Default theme implementation to present a list of reference footnotes. + * + * Available variables: + * - footnotess: A list of footnotes + * - notes: A list of free-form notes + * - references: A list of citations + * - attributes: HTML attributes for the container element. + * + * @see template_preprocess_footnote_list(). + * + * @ingroup themeable + */ +#} + + + {{ notes }} + {{ references }} +