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

Publish/Core/FieldType/Page/PageService.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\FieldType\Page;
8
9 use eZ\Publish\API\Repository\ContentService;
10 use eZ\Publish\Core\Base\Exceptions\NotFoundException;
11 use eZ\Publish\Core\FieldType\Page\PageStorage\Gateway;
12 use eZ\Publish\Core\FieldType\Page\Parts\Block;
13 use RuntimeException;
14 use OutOfBoundsException;
15 use SplObjectStorage;
16
17 class PageService
18 {
24 protected $zoneDefinition;
25
31 protected $blockDefinition;
32
34 protected $storageGateway;
35
41 protected $validBlockItems;
42
48 protected $lastValidItems;
49
55 protected $waitingBlockItems;
56
62 protected $archivedBlockItems;
63
69 protected $blocksById;
70
72 protected $contentService;
73
82 public function __construct(
83 ContentService $contentService,
84 array $zoneDefinition = [],
85 array $blockDefinition = []
86 ) {
87 $this->contentService = $contentService;
88 $this->zoneDefinition = $zoneDefinition;
89 $this->blockDefinition = $blockDefinition;
90 $this->validBlockItems = new SplObjectStorage();
91 $this->lastValidItems = new SplObjectStorage();
92 $this->waitingBlockItems = new SplObjectStorage();
93 $this->archivedBlockItems = new SplObjectStorage();
94 $this->blocksById = [];
95 }
96
102 public function getZoneDefinition()
103 {
104 return $this->zoneDefinition;
105 }
106
117 public function getZoneDefinitionByLayout($layoutIdentifier)
118 {
119 if (!isset($this->zoneDefinition[$layoutIdentifier])) {
120 throw new OutOfBoundsException("Could not find an ezpage zone definition block for given layout '$layoutIdentifier'");
121 }
122
123 return $this->zoneDefinition[$layoutIdentifier];
124 }
125
133 public function getLayoutTemplate($layoutIdentifier)
134 {
135 $def = $this->getZoneDefinitionByLayout($layoutIdentifier);
136
137 return $def['template'];
138 }
139
147 public function hasZoneLayout($layoutIdentifier)
148 {
149 return isset($this->zoneDefinition[$layoutIdentifier]);
150 }
151
157 public function getAvailableZoneLayouts()
158 {
159 return array_keys($this->zoneDefinition);
160 }
161
167 public function getBlockDefinition()
168 {
169 return $this->blockDefinition;
170 }
171
181 public function getBlockDefinitionByIdentifier($blockIdentifier)
182 {
183 if (!isset($this->blockDefinition[$blockIdentifier])) {
184 throw new OutOfBoundsException("Could not find an ezpage block definition for given identifier '$blockIdentifier'");
185 }
186
187 return $this->blockDefinition[$blockIdentifier];
188 }
189
197 public function hasBlockDefinition($blockIdentifier)
198 {
199 return isset($this->blockDefinition[$blockIdentifier]);
200 }
201
207 public function setStorageGateway(Gateway $storageGateway)
208 {
209 $this->storageGateway = $storageGateway;
210 }
211
217 public function hasStorageGateway()
218 {
219 return isset($this->storageGateway);
220 }
221
227 protected function getStorageGateway()
228 {
229 if (!$this->hasStorageGateway()) {
230 throw new RuntimeException('Missing storage gateway for Page field type.');
231 }
232
233 return $this->storageGateway;
234 }
235
243 public function getValidBlockItems(Block $block)
244 {
245 if (isset($this->validBlockItems[$block])) {
246 return $this->validBlockItems[$block];
247 }
248
249 return $this->validBlockItems[$block] = $this->getStorageGateway()->getValidBlockItems($block);
250 }
251
259 public function getLastValidBlockItem(Block $block)
260 {
261 if (isset($this->lastValidItems[$block])) {
262 return $this->lastValidItems[$block];
263 }
264
265 return $this->lastValidItems[$block] = $this->getStorageGateway()->getLastValidBlockItem($block);
266 }
267
275 public function getWaitingBlockItems(Block $block)
276 {
277 if (isset($this->waitingBlockItems[$block])) {
278 return $this->waitingBlockItems[$block];
279 }
280
281 return $this->waitingBlockItems[$block] = $this->getStorageGateway()->getWaitingBlockItems($block);
282 }
283
291 public function getArchivedBlockItems(Block $block)
292 {
293 if (isset($this->archivedBlockItems[$block])) {
294 return $this->archivedBlockItems[$block];
295 }
296
297 return $this->archivedBlockItems[$block] = $this->getStorageGateway()->getArchivedBlockItems($block);
298 }
299
309 public function loadBlock($id)
310 {
311 if (isset($this->blocksById[$id])) {
312 return $this->blocksById[$id];
313 }
314
315 $contentId = $this->getStorageGateway()->getContentIdByBlockId($id);
316 $content = $this->contentService->loadContent($contentId);
317
318 foreach ($content->getFields() as $field) {
319 if (!$field->value instanceof Value) {
320 continue;
321 }
322
323 foreach ($field->value->page->zones as $zone) {
324 foreach ($zone->blocks as $block) {
325 if ($block->id === $id) {
326 return $this->blocksById[$id] = $block;
327 }
328 }
329 }
330 }
331
332 throw new NotFoundException('Block', $id);
333 }
334 }
eZ\Publish\Core\Base\Exceptions\NotFoundException
Not Found Exception implementation.
Definition: Core/Base/Exceptions/NotFoundException.php:21
eZ\Publish\Core\FieldType\Page\PageService
Definition: Publish/Core/FieldType/Page/PageService.php:18
eZ\Publish\Core\FieldType\Page\PageService\$storageGateway
$storageGateway
Definition: Publish/Core/FieldType/Page/PageService.php:34
eZ\Publish\Core\FieldType\Page\PageService\getArchivedBlockItems
getArchivedBlockItems(Block $block)
Returns archived items (that were previously displayed), for a given block.
Definition: Publish/Core/FieldType/Page/PageService.php:291
eZ\Publish\Core\FieldType\Page\PageService\__construct
__construct(ContentService $contentService, array $zoneDefinition=[], array $blockDefinition=[])
Constructor.
Definition: Publish/Core/FieldType/Page/PageService.php:82
eZ\Publish\Core\FieldType\Page\PageService\getAvailableZoneLayouts
getAvailableZoneLayouts()
Returns list of available zone layouts.
Definition: Publish/Core/FieldType/Page/PageService.php:157
eZ\Publish\Core\FieldType\Page\PageService\$blockDefinition
$blockDefinition
Definition: Publish/Core/FieldType/Page/PageService.php:31
eZ\Publish\Core\FieldType\Page\PageService\getZoneDefinitionByLayout
getZoneDefinitionByLayout($layoutIdentifier)
Returns a zone definition for a given layout.
Definition: Publish/Core/FieldType/Page/PageService.php:117
eZ\Publish\Core\FieldType\Page\PageService\getZoneDefinition
getZoneDefinition()
Returns zone definition as an array.
Definition: Publish/Core/FieldType/Page/PageService.php:102
eZ\Publish\Core\FieldType\Page\PageService\$archivedBlockItems
$archivedBlockItems
Definition: Publish/Core/FieldType/Page/PageService.php:62
eZ\Publish\Core\FieldType\Page\PageService\$blocksById
$blocksById
Definition: Publish/Core/FieldType/Page/PageService.php:69
eZ\Publish\Core\FieldType\Page\PageService\$lastValidItems
$lastValidItems
Definition: Publish/Core/FieldType/Page/PageService.php:48
eZ\Publish\Core\FieldType\Page\PageService\getStorageGateway
getStorageGateway()
Definition: Publish/Core/FieldType/Page/PageService.php:227
eZ\Publish\Core\FieldType\Page\PageService\getValidBlockItems
getValidBlockItems(Block $block)
Returns valid items (that are to be displayed), for a given block.
Definition: Publish/Core/FieldType/Page/PageService.php:243
eZ\Publish\Core\FieldType\Page\PageService\getLayoutTemplate
getLayoutTemplate($layoutIdentifier)
Returns the template to use for given layout.
Definition: Publish/Core/FieldType/Page/PageService.php:133
eZ\Publish\Core\FieldType\Page\PageService\$zoneDefinition
$zoneDefinition
Definition: Publish/Core/FieldType/Page/PageService.php:24
eZ\Publish\Core\FieldType\Page\PageService\getLastValidBlockItem
getLastValidBlockItem(Block $block)
Returns the last valid item, for a given block.
Definition: Publish/Core/FieldType/Page/PageService.php:259
eZ\Publish\Core\FieldType\Page\PageService\$contentService
$contentService
Definition: Publish/Core/FieldType/Page/PageService.php:72
eZ\Publish\Core\FieldType\Page\PageService\setStorageGateway
setStorageGateway(Gateway $storageGateway)
Injects the storage gateway to interact with.
Definition: Publish/Core/FieldType/Page/PageService.php:207
eZ\Publish\Core\FieldType\Page\PageService\$validBlockItems
$validBlockItems
Definition: Publish/Core/FieldType/Page/PageService.php:41
eZ\Publish\Core\FieldType\Page\PageService\hasZoneLayout
hasZoneLayout($layoutIdentifier)
Checks if zone definition contains a layout having $layoutIdentifier as identifier.
Definition: Publish/Core/FieldType/Page/PageService.php:147
eZ\Publish\Core\FieldType\Page\PageService\loadBlock
loadBlock($id)
Loads Block object for the given $id.
Definition: Publish/Core/FieldType/Page/PageService.php:309
eZ\Publish\Core\FieldType\Page\PageService\$waitingBlockItems
$waitingBlockItems
Definition: Publish/Core/FieldType/Page/PageService.php:55
eZ\Publish\Core\FieldType\Page\PageService\getBlockDefinition
getBlockDefinition()
Returns block definition as an array.
Definition: Publish/Core/FieldType/Page/PageService.php:167
eZ\Publish\Core\FieldType\Page\PageService\getBlockDefinitionByIdentifier
getBlockDefinitionByIdentifier($blockIdentifier)
Returns a block definition for a given block identifier.
Definition: Publish/Core/FieldType/Page/PageService.php:181
eZ\Publish\Core\FieldType\Page\PageService\hasStorageGateway
hasStorageGateway()
Checks if storage gateway has already been injected or not.
Definition: Publish/Core/FieldType/Page/PageService.php:217
eZ\Publish\Core\FieldType\Page\PageService\getWaitingBlockItems
getWaitingBlockItems(Block $block)
Returns queued items (the next to be displayed), for a given block.
Definition: Publish/Core/FieldType/Page/PageService.php:275
eZ\Publish\Core\FieldType\Page\PageService\hasBlockDefinition
hasBlockDefinition($blockIdentifier)
Checks if block definition contains a block having $blockIdentifier as identifier.
Definition: Publish/Core/FieldType/Page/PageService.php:197
eZ\Publish\Core\FieldType\Page\PageStorage\Gateway
Main abstract storage gateway for Page field type.
Definition: FieldType/Page/PageStorage/Gateway.php:16
eZ\Publish\Core\FieldType\Page\Parts\Block
Definition: FieldType/Page/Parts/Block.php:22
eZ\Publish\Core\FieldType\Page\Value
Definition: Core/FieldType/Page/Value.php:13
eZ\Publish\API\Repository\ContentService
Definition: API/Repository/ContentService.php:27
eZ\Publish\Core\FieldType\Page\PageStorage\Gateway
Definition: Page/PageStorage/Gateway/DoctrineStorage.php:7
eZ\Publish\Core\FieldType\Page
Definition: HashConverter.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.