CiteprocPhp.php in Bibliography & Citation 8
File
src/Plugin/BibCiteProcessor/CiteprocPhp.php
View source
<?php
namespace Drupal\bibcite\Plugin\BibCiteProcessor;
use AcademicPuma\CiteProc\CiteProc;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\bibcite\Plugin\BibCiteProcessorBase;
use Drupal\bibcite\Plugin\BibCiteProcessorInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class CiteprocPhp extends BibCiteProcessorBase implements BibCiteProcessorInterface, ContainerFactoryPluginInterface {
protected $configFactory;
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('config.factory'));
}
public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->configFactory = $config_factory;
}
public function getDescription() {
return $this
->t('Render citation by citeproc-php library');
}
public function render($data, $csl, $lang) {
$cite_proc = new CiteProc($csl, $lang);
if (!$data instanceof \stdClass) {
$data = json_decode(json_encode($data));
}
return $cite_proc
->render($data);
}
}
Classes
Name |
Description |
CiteprocPhp |
Defines a style provider based on citeproc-php library. |