NodePreviewConverter.php

Same filename in this branch
  1. 9 core/modules/node/src/ProxyClass/ParamConverter/NodePreviewConverter.php
Same filename in other branches
  1. 8.9.x core/modules/node/src/ProxyClass/ParamConverter/NodePreviewConverter.php
  2. 8.9.x core/modules/node/src/ParamConverter/NodePreviewConverter.php
  3. 10 core/modules/node/src/ProxyClass/ParamConverter/NodePreviewConverter.php
  4. 10 core/modules/node/src/ParamConverter/NodePreviewConverter.php
  5. 11.x core/modules/node/src/ProxyClass/ParamConverter/NodePreviewConverter.php
  6. 11.x core/modules/node/src/ParamConverter/NodePreviewConverter.php

Namespace

Drupal\node\ParamConverter

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;

/**
 * Provides upcasting for a node entity in preview.
 */
class NodePreviewConverter implements ParamConverterInterface {
    
    /**
     * Stores the tempstore factory.
     *
     * @var \Drupal\Core\TempStore\PrivateTempStoreFactory
     */
    protected $tempStoreFactory;
    
    /**
     * Constructs a new NodePreviewConverter.
     *
     * @param \Drupal\Core\TempStore\PrivateTempStoreFactory $temp_store_factory
     *   The factory for the temp store object.
     */
    public function __construct(PrivateTempStoreFactory $temp_store_factory) {
        $this->tempStoreFactory = $temp_store_factory;
    }
    
    /**
     * {@inheritdoc}
     */
    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();
        }
    }
    
    /**
     * {@inheritdoc}
     */
    public function applies($definition, $name, Route $route) {
        if (!empty($definition['type']) && $definition['type'] == 'node_preview') {
            return TRUE;
        }
        return FALSE;
    }

}

Classes

Title Deprecated Summary
NodePreviewConverter Provides upcasting for a node entity in preview.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.