annotate core/modules/node/src/ParamConverter/NodePreviewConverter.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 1fec387a4317
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\node\ParamConverter;
Chris@0 4
Chris@14 5 use Drupal\Core\TempStore\PrivateTempStoreFactory;
Chris@0 6 use Symfony\Component\Routing\Route;
Chris@0 7 use Drupal\Core\ParamConverter\ParamConverterInterface;
Chris@0 8
Chris@0 9 /**
Chris@0 10 * Provides upcasting for a node entity in preview.
Chris@0 11 */
Chris@0 12 class NodePreviewConverter implements ParamConverterInterface {
Chris@0 13
Chris@0 14 /**
Chris@0 15 * Stores the tempstore factory.
Chris@0 16 *
Chris@14 17 * @var \Drupal\Core\TempStore\PrivateTempStoreFactory
Chris@0 18 */
Chris@0 19 protected $tempStoreFactory;
Chris@0 20
Chris@0 21 /**
Chris@0 22 * Constructs a new NodePreviewConverter.
Chris@0 23 *
Chris@14 24 * @param \Drupal\Core\TempStore\PrivateTempStoreFactory $temp_store_factory
Chris@0 25 * The factory for the temp store object.
Chris@0 26 */
Chris@0 27 public function __construct(PrivateTempStoreFactory $temp_store_factory) {
Chris@0 28 $this->tempStoreFactory = $temp_store_factory;
Chris@0 29 }
Chris@0 30
Chris@0 31 /**
Chris@0 32 * {@inheritdoc}
Chris@0 33 */
Chris@0 34 public function convert($value, $definition, $name, array $defaults) {
Chris@0 35 $store = $this->tempStoreFactory->get('node_preview');
Chris@0 36 if ($form_state = $store->get($value)) {
Chris@0 37 return $form_state->getFormObject()->getEntity();
Chris@0 38 }
Chris@0 39 }
Chris@0 40
Chris@0 41 /**
Chris@0 42 * {@inheritdoc}
Chris@0 43 */
Chris@0 44 public function applies($definition, $name, Route $route) {
Chris@0 45 if (!empty($definition['type']) && $definition['type'] == 'node_preview') {
Chris@0 46 return TRUE;
Chris@0 47 }
Chris@0 48 return FALSE;
Chris@0 49 }
Chris@0 50
Chris@0 51 }