-
-
Notifications
You must be signed in to change notification settings - Fork 221
/
ContentContext.php
186 lines (170 loc) · 5.92 KB
/
ContentContext.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?php
namespace Neos\Neos\Domain\Service;
/*
* This file is part of the Neos.Neos package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Log\Utility\LogEnvironment;
use Neos\Flow\Persistence\Exception\IllegalObjectTypeException;
use Neos\Flow\Security\Authorization\PrivilegeManagerInterface;
use Neos\Flow\Security\Exception;
use Neos\Neos\Domain\Model\Domain;
use Neos\Neos\Domain\Model\UserInterfaceMode;
use Neos\Neos\Domain\Model\Site;
use Neos\ContentRepository\Domain\Model\NodeInterface;
use Neos\ContentRepository\Domain\Service\Context;
use Neos\ContentRepository\Domain\Utility\NodePaths;
/**
* The Content Context
*
* @Flow\Scope("prototype")
* @api
*/
class ContentContext extends Context
{
/**
* @var Site
*/
protected $currentSite;
/**
* @var Domain
*/
protected $currentDomain;
/**
* @var NodeInterface
*/
protected $currentSiteNode;
/**
* @Flow\Inject
* @var PrivilegeManagerInterface
*/
protected $privilegeManager;
/**
* @Flow\Inject
* @var UserInterfaceModeService
*/
protected $interfaceRenderModeService;
/**
* Creates a new Content Context object.
*
* NOTE: This is for internal use only, you should use the ContextFactory for creating Context instances.
*
* @param string $workspaceName Name of the current workspace
* @param \DateTimeInterface $currentDateTime The current date and time
* @param array $dimensions Array of dimensions with array of ordered values
* @param array $targetDimensions Array of dimensions used when creating / modifying content
* @param boolean $invisibleContentShown If invisible content should be returned in query results
* @param boolean $removedContentShown If removed content should be returned in query results
* @param boolean $inaccessibleContentShown If inaccessible content should be returned in query results
* @param Site $currentSite The current Site object
* @param Domain $currentDomain The current Domain object
* @see ContextFactoryInterface
*/
public function __construct($workspaceName, \DateTimeInterface $currentDateTime, array $dimensions, array $targetDimensions, $invisibleContentShown, $removedContentShown, $inaccessibleContentShown, Site $currentSite = null, Domain $currentDomain = null)
{
parent::__construct($workspaceName, $currentDateTime, $dimensions, $targetDimensions, $invisibleContentShown, $removedContentShown, $inaccessibleContentShown);
$this->currentSite = $currentSite;
$this->currentDomain = $currentDomain;
$this->targetDimensions = $targetDimensions;
}
/**
* Returns the current site from this frontend context
*
* @return Site The current site
*/
public function getCurrentSite()
{
return $this->currentSite;
}
/**
* Returns the current domain from this frontend context
*
* @return Domain The current domain
* @api
*/
public function getCurrentDomain()
{
return $this->currentDomain;
}
/**
* Returns the node of the current site.
*
* @return NodeInterface
*/
public function getCurrentSiteNode()
{
if ($this->currentSite !== null && $this->currentSiteNode === null) {
$siteNodePath = NodePaths::addNodePathSegment(SiteService::SITES_ROOT_PATH, $this->currentSite->getNodeName());
$this->currentSiteNode = $this->getNode($siteNodePath);
if (!($this->currentSiteNode instanceof NodeInterface)) {
$this->systemLogger->warning(sprintf('Couldn\'t load the site node for path "%s" in workspace "%s". This is probably due to a missing baseworkspace for the workspace of the current user.', $siteNodePath, $this->workspaceName), LogEnvironment::fromMethodName(__METHOD__));
}
}
return $this->currentSiteNode;
}
/**
* Returns the properties of this context.
*
* @return array
*/
public function getProperties()
{
return [
'workspaceName' => $this->workspaceName,
'currentDateTime' => $this->currentDateTime,
'dimensions' => $this->dimensions,
'targetDimensions' => $this->targetDimensions,
'invisibleContentShown' => $this->invisibleContentShown,
'removedContentShown' => $this->removedContentShown,
'inaccessibleContentShown' => $this->inaccessibleContentShown,
'currentSite' => $this->currentSite,
'currentDomain' => $this->currentDomain
];
}
/**
* Returns true if current context is live workspace, false otherwise
*
* @return bool
* @throws IllegalObjectTypeException
*/
public function isLive(): bool
{
return ($this->getWorkspace()->getBaseWorkspace() === null);
}
/**
* Returns true while rendering backend (not live workspace and access to backend granted), false otherwise
*
* @return boolean
* @throws IllegalObjectTypeException
*/
public function isInBackend(): bool
{
return (!$this->isLive() && $this->hasAccessToBackend());
}
/**
* @return UserInterfaceMode
*/
public function getCurrentRenderingMode(): UserInterfaceMode
{
return $this->interfaceRenderModeService->findModeByCurrentUser();
}
/**
* Is access to the neos backend granted by current authentications.
*
* @return bool
*/
protected function hasAccessToBackend(): bool
{
try {
return $this->privilegeManager->isPrivilegeTargetGranted('Neos.Neos:Backend.GeneralAccess');
} catch (Exception $exception) {
return false;
}
}
}