Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

ContentPreviewHelper.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\Helper;
8
9 use eZ\Publish\API\Repository\Values\Content\Content;
10 use eZ\Publish\API\Repository\Values\Content\Location;
11 use eZ\Publish\Core\MVC\Symfony\Event\ScopeChangeEvent;
12 use eZ\Publish\Core\MVC\Symfony\MVCEvents;
13 use eZ\Publish\Core\MVC\Symfony\SiteAccess\SiteAccessAware;
14 use eZ\Publish\Core\MVC\Symfony\SiteAccess;
15 use eZ\Publish\Core\MVC\Symfony\SiteAccess\SiteAccessRouterInterface;
16 use Symfony\Component\EventDispatcher\EventDispatcherInterface;
17
18 class ContentPreviewHelper implements SiteAccessAware
19 {
21 protected $eventDispatcher;
22
24 protected $siteAccessRouter;
25
27 protected $originalSiteAccess;
28
30 private $previewActive = false;
31
33 private $previewedContent;
34
36 private $previewedLocation;
37
38 public function __construct(EventDispatcherInterface $eventDispatcher, SiteAccessRouterInterface $siteAccessRouter)
39 {
40 $this->eventDispatcher = $eventDispatcher;
41 $this->siteAccessRouter = $siteAccessRouter;
42 }
43
44 public function setSiteAccess(SiteAccess $siteAccess = null)
45 {
46 $this->originalSiteAccess = $siteAccess;
47 }
48
54 public function getOriginalSiteAccess()
55 {
56 return $this->originalSiteAccess;
57 }
58
66 public function changeConfigScope($siteAccessName)
67 {
68 $event = new ScopeChangeEvent($this->siteAccessRouter->matchByName($siteAccessName));
69 $this->eventDispatcher->dispatch(MVCEvents::CONFIG_SCOPE_CHANGE, $event);
70
71 return $event->getSiteAccess();
72 }
73
79 public function restoreConfigScope()
80 {
81 $event = new ScopeChangeEvent($this->originalSiteAccess);
82 $this->eventDispatcher->dispatch(MVCEvents::CONFIG_SCOPE_RESTORE, $event);
83
84 return $event->getSiteAccess();
85 }
86
90 public function isPreviewActive()
91 {
92 return $this->previewActive;
93 }
94
98 public function setPreviewActive($previewActive)
99 {
100 $this->previewActive = (bool)$previewActive;
101 }
102
106 public function getPreviewedContent()
107 {
108 return $this->previewedContent;
109 }
110
114 public function setPreviewedContent(Content $previewedContent)
115 {
116 $this->previewedContent = $previewedContent;
117 }
118
122 public function getPreviewedLocation()
123 {
124 return $this->previewedLocation;
125 }
126
130 public function setPreviewedLocation(Location $previewedLocation)
131 {
132 $this->previewedLocation = $previewedLocation;
133 }
134 }
eZ\Publish\API\Repository\Values\Content\Content
Definition: Publish/API/Repository/Values/Content/Content.php:21
eZ\Publish\API\Repository\Values\Content\Location
Definition: API/Repository/Values/Content/Location.php:32
eZ\Publish\Core\Helper\ContentPreviewHelper
Definition: ContentPreviewHelper.php:19
eZ\Publish\Core\Helper\ContentPreviewHelper\changeConfigScope
changeConfigScope($siteAccessName)
Switches configuration scope to $siteAccessName and returns the new SiteAccess to use for preview.
Definition: ContentPreviewHelper.php:66
eZ\Publish\Core\Helper\ContentPreviewHelper\$previewedLocation
$previewedLocation
Definition: ContentPreviewHelper.php:36
eZ\Publish\Core\Helper\ContentPreviewHelper\setSiteAccess
setSiteAccess(SiteAccess $siteAccess=null)
Definition: ContentPreviewHelper.php:44
eZ\Publish\Core\Helper\ContentPreviewHelper\setPreviewedContent
setPreviewedContent(Content $previewedContent)
Definition: ContentPreviewHelper.php:114
eZ\Publish\Core\Helper\ContentPreviewHelper\getPreviewedContent
getPreviewedContent()
Definition: ContentPreviewHelper.php:106
eZ\Publish\Core\Helper\ContentPreviewHelper\$siteAccessRouter
$siteAccessRouter
Definition: ContentPreviewHelper.php:24
eZ\Publish\Core\Helper\ContentPreviewHelper\restoreConfigScope
restoreConfigScope()
Restores original config scope.
Definition: ContentPreviewHelper.php:79
eZ\Publish\Core\Helper\ContentPreviewHelper\$previewActive
$previewActive
Definition: ContentPreviewHelper.php:30
eZ\Publish\Core\Helper\ContentPreviewHelper\__construct
__construct(EventDispatcherInterface $eventDispatcher, SiteAccessRouterInterface $siteAccessRouter)
Definition: ContentPreviewHelper.php:38
eZ\Publish\Core\Helper\ContentPreviewHelper\$originalSiteAccess
$originalSiteAccess
Definition: ContentPreviewHelper.php:27
eZ\Publish\Core\Helper\ContentPreviewHelper\setPreviewedLocation
setPreviewedLocation(Location $previewedLocation)
Definition: ContentPreviewHelper.php:130
eZ\Publish\Core\Helper\ContentPreviewHelper\$eventDispatcher
$eventDispatcher
Definition: ContentPreviewHelper.php:21
eZ\Publish\Core\Helper\ContentPreviewHelper\setPreviewActive
setPreviewActive($previewActive)
Definition: ContentPreviewHelper.php:98
eZ\Publish\Core\Helper\ContentPreviewHelper\$previewedContent
$previewedContent
Definition: ContentPreviewHelper.php:33
eZ\Publish\Core\Helper\ContentPreviewHelper\getOriginalSiteAccess
getOriginalSiteAccess()
Return original SiteAccess.
Definition: ContentPreviewHelper.php:54
eZ\Publish\Core\Helper\ContentPreviewHelper\isPreviewActive
isPreviewActive()
Definition: ContentPreviewHelper.php:90
eZ\Publish\Core\Helper\ContentPreviewHelper\getPreviewedLocation
getPreviewedLocation()
Definition: ContentPreviewHelper.php:122
eZ\Publish\Core\MVC\Symfony\Event\ScopeChangeEvent
This event is sent when configuration scope is changed (e.g.
Definition: ScopeChangeEvent.php:16
eZ\Publish\Core\MVC\Symfony\MVCEvents
Definition: MVCEvents.php:10
eZ\Publish\Core\MVC\Symfony\MVCEvents\CONFIG_SCOPE_RESTORE
const CONFIG_SCOPE_RESTORE
CONFIG_SCOPE_RESTORE event occurs when original configuration scope is restored.
Definition: MVCEvents.php:61
eZ\Publish\Core\MVC\Symfony\MVCEvents\CONFIG_SCOPE_CHANGE
const CONFIG_SCOPE_CHANGE
CONFIG_SCOPE_CHANGE event occurs when configuration scope is changed (e.g.
Definition: MVCEvents.php:53
eZ\Publish\Core\MVC\Symfony\SiteAccess
Base struct for a siteaccess representation.
Definition: SiteAccess.php:16
eZ\Publish\Core\MVC\Symfony\SiteAccess\SiteAccessAware
Interface for SiteAccess aware services.
Definition: SiteAccessAware.php:15
eZ\Publish\Core\MVC\Symfony\SiteAccess\SiteAccessRouterInterface
Definition: SiteAccessRouterInterface.php:12
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.