ReferencePreviewConverter.php in Bibliography & Citation 2.0.x
Same filename and directory in other branches
Namespace
Drupal\bibcite_entity\ParamConverterFile
modules/bibcite_entity/src/ParamConverter/ReferencePreviewConverter.phpView source
<?php
namespace Drupal\bibcite_entity\ParamConverter;
use Drupal\Core\TempStore\PrivateTempStoreFactory;
use Symfony\Component\Routing\Route;
use Drupal\Core\ParamConverter\ParamConverterInterface;
/**
* Provides upcasting for a reference entity in preview.
*/
class ReferencePreviewConverter implements ParamConverterInterface {
/**
* Stores the tempstore factory.
*
* @var \Drupal\Core\TempStore\PrivateTempStoreFactory
*/
protected $tempStoreFactory;
/**
* Constructs a new ReferencePreviewConverter.
*
* @param \Drupal\Core\TempStore\PrivateTempStoreFactory $temp_store_factory
* The factory for the temp store object.
*/
public function __construct(PrivateTempStoreFactory $temp_store_factory) {
$this->tempStoreFactory = $temp_store_factory;
}
/**
* {@inheritdoc}
*/
public function convert($value, $definition, $name, array $defaults) {
$store = $this->tempStoreFactory
->get('bibcite_reference_preview');
if ($form_state = $store
->get($value)) {
return $form_state
->getFormObject()
->getEntity();
}
}
/**
* {@inheritdoc}
*/
public function applies($definition, $name, Route $route) {
if (!empty($definition['type']) && $definition['type'] == 'bibcite_reference_preview') {
return TRUE;
}
return FALSE;
}
}
Classes
Name | Description |
---|---|
ReferencePreviewConverter | Provides upcasting for a reference entity in preview. |