|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* File containing the ContentView class. |
|
5
|
|
|
* |
|
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
|
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
namespace eZ\Publish\Core\MVC\Symfony\View; |
|
10
|
|
|
|
|
11
|
|
|
use eZ\Publish\API\Repository\Values\Content\Content; |
|
12
|
|
|
use eZ\Publish\API\Repository\Values\Content\Location; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Main object to be rendered by the View Manager when viewing a content. |
|
16
|
|
|
* Holds the path to the template to be rendered by the view manager and the parameters to inject in it. |
|
17
|
|
|
* |
|
18
|
|
|
* The template path can be a closure. In that case, the view manager will invoke it instead of loading a template. |
|
19
|
|
|
* $parameters will be passed to the callable in addition to the Content or Location object (depending on the context). |
|
20
|
|
|
* The prototype of the closure must be : |
|
21
|
|
|
* <code> |
|
22
|
|
|
* namespace Foo; |
|
23
|
|
|
* use eZ\Publish\API\Repository\Values\Content\ContentInfo; |
|
24
|
|
|
* use eZ\Publish\API\Repository\Values\Content\Location; |
|
25
|
|
|
* |
|
26
|
|
|
* // For a content |
|
27
|
|
|
* function ( ContentInfo $contentInfo, array $parameters = array() ) |
|
28
|
|
|
* { |
|
29
|
|
|
* // Do something to render |
|
30
|
|
|
* // Must return a string to display |
|
31
|
|
|
* } |
|
32
|
|
|
* |
|
33
|
|
|
* // For a location |
|
34
|
|
|
* function ( Location $location, array $parameters = array() ) |
|
35
|
|
|
* { |
|
36
|
|
|
* // Do something to render |
|
37
|
|
|
* // Must return a string to display |
|
38
|
|
|
* } |
|
39
|
|
|
* </code> |
|
40
|
|
|
*/ |
|
41
|
|
|
class ContentView extends BaseView implements View, ContentValueView, LocationValueView, EmbedView, CachableView, RelationView |
|
42
|
|
|
{ |
|
43
|
|
|
/** @var \eZ\Publish\API\Repository\Values\Content\Content */ |
|
44
|
|
|
private $content; |
|
45
|
|
|
|
|
46
|
|
|
/** @var \eZ\Publish\API\Repository\Values\Content\Location|null */ |
|
47
|
|
|
private $location; |
|
48
|
|
|
|
|
49
|
|
|
/** @var \eZ\Publish\API\Repository\Values\Content\Relation[] */ |
|
50
|
|
|
private $relations = []; |
|
51
|
|
|
|
|
52
|
|
|
/** @var bool */ |
|
53
|
|
|
private $isEmbed = false; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Content $content |
|
57
|
|
|
*/ |
|
58
|
|
|
public function setContent(Content $content) |
|
59
|
|
|
{ |
|
60
|
|
|
$this->content = $content; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Returns the Content. |
|
65
|
|
|
* |
|
66
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Content |
|
67
|
|
|
*/ |
|
68
|
|
|
public function getContent() |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->content; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Location $location |
|
75
|
|
|
*/ |
|
76
|
|
|
public function setLocation(Location $location) |
|
77
|
|
|
{ |
|
78
|
|
|
$this->location = $location; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Location |
|
83
|
|
|
*/ |
|
84
|
|
|
public function getLocation() |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->location; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Relation[] $relations |
|
91
|
|
|
*/ |
|
92
|
|
|
public function setRelations($relations) |
|
93
|
|
|
{ |
|
94
|
|
|
$this->relations = $relations; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Relation[] |
|
99
|
|
|
*/ |
|
100
|
|
|
public function getRelations() |
|
101
|
|
|
{ |
|
102
|
|
|
return $this->relations; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
protected function getInternalParameters() |
|
106
|
|
|
{ |
|
107
|
|
|
$parameters = ['content' => $this->content]; |
|
108
|
|
|
if ($this->location !== null) { |
|
109
|
|
|
$parameters['location'] = $this->location; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
return $parameters; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* Sets the value as embed / not embed. |
|
117
|
|
|
* |
|
118
|
|
|
* @param bool $value |
|
119
|
|
|
*/ |
|
120
|
|
|
public function setIsEmbed($value) |
|
121
|
|
|
{ |
|
122
|
|
|
$this->isEmbed = (bool)$value; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Is the view an embed or not. |
|
127
|
|
|
* @return bool True if the view is an embed, false if it is not. |
|
128
|
|
|
*/ |
|
129
|
|
|
public function isEmbed() |
|
130
|
|
|
{ |
|
131
|
|
|
return $this->isEmbed; |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|