NodePreviewConverter.php in Drupal 9
File
core/modules/node/src/ParamConverter/NodePreviewConverter.php
View source
<?php
namespace Drupal\node\ParamConverter;
use Drupal\Core\TempStore\PrivateTempStoreFactory;
use Symfony\Component\Routing\Route;
use Drupal\Core\ParamConverter\ParamConverterInterface;
class NodePreviewConverter implements ParamConverterInterface {
protected $tempStoreFactory;
public function __construct(PrivateTempStoreFactory $temp_store_factory) {
$this->tempStoreFactory = $temp_store_factory;
}
public function convert($value, $definition, $name, array $defaults) {
$store = $this->tempStoreFactory
->get('node_preview');
if ($form_state = $store
->get($value)) {
return $form_state
->getFormObject()
->getEntity();
}
}
public function applies($definition, $name, Route $route) {
if (!empty($definition['type']) && $definition['type'] == 'node_preview') {
return TRUE;
}
return FALSE;
}
}