Newer
Older
Angie Byron
committed
<?php
/**
* @file
* Contains \Drupal\node\ParamConverter\NodePreviewConverter.
*/
namespace Drupal\node\ParamConverter;
Angie Byron
committed
use Drupal\user\PrivateTempStoreFactory;
Angie Byron
committed
use Symfony\Component\Routing\Route;
use Drupal\Core\ParamConverter\ParamConverterInterface;
/**
* Provides upcasting for a node entity in preview.
*/
class NodePreviewConverter implements ParamConverterInterface {
/**
* Stores the tempstore factory.
*
Angie Byron
committed
* @var \Drupal\user\PrivateTempStoreFactory
Angie Byron
committed
*/
protected $tempStoreFactory;
/**
* Constructs a new NodePreviewConverter.
*
Angie Byron
committed
* @param \Drupal\user\PrivateTempStoreFactory $temp_store_factory
Angie Byron
committed
* The factory for the temp store object.
*/
Angie Byron
committed
public function __construct(PrivateTempStoreFactory $temp_store_factory) {
Angie Byron
committed
$this->tempStoreFactory = $temp_store_factory;
}
/**
* {@inheritdoc}
*/
public function convert($value, $definition, $name, array $defaults) {
Angie Byron
committed
$store = $this->tempStoreFactory->get('node_preview');
if ($form_state = $store->get($value)) {
return $form_state->getFormObject()->getEntity();
Angie Byron
committed
}
}
/**
* {@inheritdoc}
*/
public function applies($definition, $name, Route $route) {
if (!empty($definition['type']) && $definition['type'] == 'node_preview') {
return TRUE;
}
return FALSE;
}
}