Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/node/src/ParamConverter/NodePreviewConverter.php @ 0:c75dbcec494b
Initial commit from drush-created site
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2018 14:24:15 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c75dbcec494b |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\node\ParamConverter; | |
4 | |
5 use Drupal\Core\TempStore\PrivateTempStoreFactory; | |
6 use Symfony\Component\Routing\Route; | |
7 use Drupal\Core\ParamConverter\ParamConverterInterface; | |
8 | |
9 /** | |
10 * Provides upcasting for a node entity in preview. | |
11 */ | |
12 class NodePreviewConverter implements ParamConverterInterface { | |
13 | |
14 /** | |
15 * Stores the tempstore factory. | |
16 * | |
17 * @var \Drupal\Core\TempStore\PrivateTempStoreFactory | |
18 */ | |
19 protected $tempStoreFactory; | |
20 | |
21 /** | |
22 * Constructs a new NodePreviewConverter. | |
23 * | |
24 * @param \Drupal\Core\TempStore\PrivateTempStoreFactory $temp_store_factory | |
25 * The factory for the temp store object. | |
26 */ | |
27 public function __construct(PrivateTempStoreFactory $temp_store_factory) { | |
28 $this->tempStoreFactory = $temp_store_factory; | |
29 } | |
30 | |
31 /** | |
32 * {@inheritdoc} | |
33 */ | |
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(); | |
38 } | |
39 } | |
40 | |
41 /** | |
42 * {@inheritdoc} | |
43 */ | |
44 public function applies($definition, $name, Route $route) { | |
45 if (!empty($definition['type']) && $definition['type'] == 'node_preview') { | |
46 return TRUE; | |
47 } | |
48 return FALSE; | |
49 } | |
50 | |
51 } |