diff --git a/bibcite_footnotes.module b/bibcite_footnotes.module index 07d76b0..b9585c5 100644 --- a/bibcite_footnotes.module +++ b/bibcite_footnotes.module @@ -202,9 +202,13 @@ function bibcite_footnotes_preprocess_bibcite_footnote_link(&$variables) { $title = trim(strip_tags(render($citation_data))); $url = Url::fromUserInput('#' . $fn['fn_id'], ['attributes' => ['id' => $fn['ref_id'], 'class' => $class, 'title' => $title]]); - - $link = Link::fromTextAndUrl($fn['value'], $url)->toRenderable(); +// We need to delete the cached markup to render it in a different mode. + unset($citation_data['#markup']); + unset($citation_data['#children']); + + $citation_data['#data']['mode'] = 'citation'; + $link = Link::fromTextAndUrl(render($citation_data), $url)->toRenderable(); unset($variables['fn']['fn']); $variables['fn']['fn'] = $link; // $variables['fn']['fn'][] = $link; diff --git a/src/Plugin/BibCiteProcessor/CiteprocPhpInline.php b/src/Plugin/BibCiteProcessor/CiteprocPhpInline.php new file mode 100644 index 0000000..87d320f --- /dev/null +++ b/src/Plugin/BibCiteProcessor/CiteprocPhpInline.php @@ -0,0 +1,73 @@ +get('config.factory') + ); + } + + /** + * {@inheritdoc} + */ + public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory) { + parent::__construct($configuration, $plugin_id, $plugin_definition); + + $this->configFactory = $config_factory; + } + + /** + * {@inheritdoc} + */ + public function getDescription() { + return $this->t('Render citation by citeproc-php library'); + } + + /** + * {@inheritdoc} + */ + public function render($data, $csl, $lang) { + $cite_proc = new CiteProc($csl, $lang); + $mode = !empty($data['mode']) ? $data['mode'] : NULL; + + if (!$data instanceof \stdClass) { + $data = json_decode(json_encode($data)); + } + + return $cite_proc->render($data, $mode); + } + +}