3 namespace Drupal\node\ParamConverter;
5 use Drupal\user\PrivateTempStoreFactory;
6 use Symfony\Component\Routing\Route;
7 use Drupal\Core\ParamConverter\ParamConverterInterface;
10 * Provides upcasting for a node entity in preview.
12 class NodePreviewConverter implements ParamConverterInterface {
15 * Stores the tempstore factory.
17 * @var \Drupal\user\PrivateTempStoreFactory
19 protected $tempStoreFactory;
22 * Constructs a new NodePreviewConverter.
24 * @param \Drupal\user\PrivateTempStoreFactory $temp_store_factory
25 * The factory for the temp store object.
27 public function __construct(PrivateTempStoreFactory $temp_store_factory) {
28 $this->tempStoreFactory = $temp_store_factory;
34 public function convert($value, $definition, $name, array $defaults) {
35 $store = $this->tempStoreFactory->get('node_preview');
36 if ($form_state = $store->get($value)) {
37 return $form_state->getFormObject()->getEntity();
44 public function applies($definition, $name, Route $route) {
45 if (!empty($definition['type']) && $definition['type'] == 'node_preview') {