class NodePreviewController in Drupal 8
Same name and namespace in other branches
- 9 core/modules/node/src/Controller/NodePreviewController.php \Drupal\node\Controller\NodePreviewController
Defines a controller to render a single node in preview.
Hierarchy
- class \Drupal\Core\Entity\Controller\EntityViewController implements ContainerInjectionInterface, TrustedCallbackInterface uses DeprecatedServicePropertyTrait
- class \Drupal\node\Controller\NodePreviewController
Expanded class hierarchy of NodePreviewController
File
- core/
modules/ node/ src/ Controller/ NodePreviewController.php, line 15
Namespace
Drupal\node\ControllerView source
class NodePreviewController extends EntityViewController {
/**
* The entity repository service.
*
* @var \Drupal\Core\Entity\EntityRepositoryInterface
*/
protected $entityRepository;
/**
* Creates an NodeViewController object.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\Render\RendererInterface $renderer
* The renderer service.
* @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
* The entity repository.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, RendererInterface $renderer, EntityRepositoryInterface $entity_repository = NULL) {
parent::__construct($entity_type_manager, $renderer);
if (!$entity_repository) {
@trigger_error('The entity.repository service must be passed to NodePreviewController::__construct(), it is required before Drupal 9.0.0. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
$entity_repository = \Drupal::service('entity.repository');
}
$this->entityRepository = $entity_repository;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('entity_type.manager'), $container
->get('renderer'), $container
->get('entity.repository'));
}
/**
* {@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';
// Don't render cache previews.
unset($build['#cache']);
return $build;
}
/**
* The _title_callback for the page that renders a single node in preview.
*
* @param \Drupal\Core\Entity\EntityInterface $node_preview
* The current node.
*
* @return string
* The page title.
*/
public function title(EntityInterface $node_preview) {
return $this->entityRepository
->getTranslationFromContext($node_preview)
->label();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DeprecatedServicePropertyTrait:: |
public | function | Allows to access deprecated/removed properties. | |
EntityViewController:: |
protected | property | ||
EntityViewController:: |
protected | property | The entity type manager. | |
EntityViewController:: |
protected | property | The renderer service. | |
EntityViewController:: |
public | function | Pre-render callback to build the page title. | |
EntityViewController:: |
public static | function |
Lists the trusted callbacks provided by the implementing class. Overrides TrustedCallbackInterface:: |
|
EntityViewController:: |
public | function | Provides a page to render a single entity revision. | |
NodePreviewController:: |
protected | property | The entity repository service. | |
NodePreviewController:: |
public static | function |
Instantiates a new instance of this class. Overrides EntityViewController:: |
|
NodePreviewController:: |
public | function | The _title_callback for the page that renders a single node in preview. | |
NodePreviewController:: |
public | function |
Provides a page to render a single entity. Overrides EntityViewController:: |
|
NodePreviewController:: |
public | function |
Creates an NodeViewController object. Overrides EntityViewController:: |
|
TrustedCallbackInterface:: |
constant | Untrusted callbacks throw exceptions. | ||
TrustedCallbackInterface:: |
constant | Untrusted callbacks trigger silenced E_USER_DEPRECATION errors. | ||
TrustedCallbackInterface:: |
constant | Untrusted callbacks trigger E_USER_WARNING errors. |