class NodePreviewController

Same name and namespace in other branches
  1. 11.x core/modules/node/src/Controller/NodePreviewController.php \Drupal\node\Controller\NodePreviewController
  2. 10 core/modules/node/src/Controller/NodePreviewController.php \Drupal\node\Controller\NodePreviewController
  3. 9 core/modules/node/src/Controller/NodePreviewController.php \Drupal\node\Controller\NodePreviewController
  4. 8.9.x core/modules/node/src/Controller/NodePreviewController.php \Drupal\node\Controller\NodePreviewController

Defines a controller to render a single node in preview.

Hierarchy

Expanded class hierarchy of NodePreviewController

File

core/modules/node/src/Controller/NodePreviewController.php, line 17

Namespace

Drupal\node\Controller
View source
class NodePreviewController extends EntityViewController {
  
  /**
   * Creates a NodePreviewController object.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager, RendererInterface $renderer, protected readonly EntityRepositoryInterface $entityRepository, protected readonly FormBuilderInterface $formBuilder) {
    parent::__construct($entity_type_manager, $renderer);
  }
  
  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container->get('entity_type.manager'), $container->get('renderer'), $container->get('entity.repository'), $container->get('form_builder'));
  }
  
  /**
   * {@inheritdoc}
   */
  public function view(EntityInterface $node_preview, $view_mode_id = 'full', $langcode = NULL) {
    $node_preview->preview_view_mode = $view_mode_id;
    $build = parent::view($node_preview, $view_mode_id);
    $build['#attached']['library'][] = 'node/drupal.node.preview';
    $build['#attached']['page_top']['node_preview'] = [
      '#type' => 'container',
      '#attributes' => [
        'class' => [
          'node-preview-container',
          'container-inline',
        ],
      ],
      'view_mode' => $this->formBuilder
        ->getForm(NodePreviewForm::class, $node_preview),
    ];
    // Don't render cache previews.
    unset($build['#cache']);
    return $build;
  }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
EntityViewController::$entityTypeManager protected property The entity type manager.
EntityViewController::$renderer protected property The renderer service.
EntityViewController::buildTitle public function Pre-render callback to build the page title.
EntityViewController::trustedCallbacks public static function Lists the trusted callbacks provided by the implementing class. Overrides TrustedCallbackInterface::trustedCallbacks
NodePreviewController::create public static function Instantiates a new instance of this class. Overrides EntityViewController::create
NodePreviewController::view public function Provides a page to render a single entity. Overrides EntityViewController::view
NodePreviewController::__construct public function Creates a NodePreviewController object. Overrides EntityViewController::__construct
TrustedCallbackInterface::THROW_EXCEPTION constant Untrusted callbacks throw exceptions.
TrustedCallbackInterface::TRIGGER_SILENCED_DEPRECATION constant Untrusted callbacks trigger silenced E_USER_DEPRECATION errors.

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