Skip to content

Commit 5f3f688

Browse files
IBX-9415: Support for ContentAwareInterface in ibexa_* Twig functions described in Developer Documentation (#2638)
* contentaware support added * fixes * full namespaces removed * Fixes ater review * Description fix
1 parent 761ad96 commit 5f3f688

File tree

3 files changed

+83
-14
lines changed

3 files changed

+83
-14
lines changed

docs/templating/twig_function_reference/content_twig_functions.md

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ You can provide `ibexa_render()` with either a content item or a Location object
2828

2929
|Argument|Type|Description|
3030
|------|------|------|
31-
|`content`</br>or</br>`location`|`Ibexa\Contracts\Core\Repository\Values\Content\Content`</br>or</br>`Ibexa\Contracts\Core\Repository\Values\Content\Location`|Content item or its location.|
31+
|`content` or `location`|[`Content`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-Content.html) or [`Location`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-Location.html)|Content item or its location.|
3232
|`method`|`string`|(optional) [Rendering method](#rendering-methods). One of: `direct`, `inline`, `esi`, `ssi`. (Default method is `direct`)|
3333
|`viewType`|`string`|(optional) [View type](template_configuration.md#view-types). (Default view type is `embed`)|
3434

@@ -60,7 +60,7 @@ If the content item doesn't have a translation in the prioritized or passed lang
6060

6161
| Argument | Type | Description |
6262
|---------------|------|-------------|
63-
| `content` | `Ibexa\Contracts\Core\Repository\Values\Content\Content`</br>or</br>`Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo` | Content item or its ContentInfo object.|
63+
| `content` | [`Content`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-Content.html), [`ContentInfo`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-ContentInfo.html), or [`ContentAwareInterface`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-ContentAwareInterface.html) | Content item, its ContentInfo object, or ContentAwareInterface object.|
6464
| `forcedLanguage` | `string` | (optional) Language to use (for example, `fre-FR`). |
6565

6666
``` html+twig
@@ -69,30 +69,44 @@ If the content item doesn't have a translation in the prioritized or passed lang
6969
{{ ibexa_content_name(content, 'pol-PL') }}
7070
```
7171

72+
``` html+twig
73+
{{ ibexa_content_name(product) }}
74+
75+
{{ ibexa_content_name(product, 'fr-FR') }}
76+
```
77+
7278
### `ibexa_seo_is_empty()`
7379

7480
`ibexa_seo_is_empty()` returns a Boolean value which indicates whether [SEO]([[= user_doc =]]/search_engine_optimization/seo/) data is available for the content item that is passed as an argument.
7581

7682
| Argument | Type | Description |
7783
|---------------|------|-------------|
78-
| `content` | `Ibexa\Contracts\Core\Repository\Values\Content\Content`</br>or</br>`Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo` | Content item or its ContentInfo object.|
84+
| `content` | [`Content`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-Content.html) or [`ContentAwareInterface`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-ContentAwareInterface.html) | Content item or ContentAwareInterface object.|
7985

8086
``` html+twig
8187
{{ ibexa_seo_is_empty(content) }}
8288
```
8389

90+
``` html+twig
91+
{{ ibexa_seo_is_empty(product) }}
92+
```
93+
8494
### `ibexa_seo()`
8595

8696
`ibexa_seo()` attaches [SEO]([[= user_doc =]]/search_engine_optimization/seo/) data to the content item's HTML code.
8797

8898
| Argument | Type | Description |
8999
|---------------|------|-------------|
90-
| `content` | `Ibexa\Contracts\Core\Repository\Values\Content\Content`</br>or</br>`Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo` | Content item or its ContentInfo object.|
100+
| `content` | [`Content`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-Content.html) or [`ContentAwareInterface`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-ContentAwareInterface.html) | Content item or ContentAwareInterface object.|
91101

92102
``` html+twig
93103
{{ ibexa_seo(content) }}
94104
```
95105

106+
``` html+twig
107+
{{ ibexa_seo(product) }}
108+
```
109+
96110
!!! tip
97111

98112
The following example uses both SEO-related functions:
@@ -112,12 +126,15 @@ If the content item doesn't have a translation in the prioritized or passed lang
112126

113127
| Argument | Type | Description |
114128
|---------------|------|-------------|
115-
| `content` | [`Ibexa\Contracts\Core\Repository\Values\Content\Content`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-Content.html) | Content item to display the category name for. |
129+
| `content` | [`Content`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-Content.html) or [`ContentAwareInterface`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-ContentAwareInterface.html) | Content item to display the category name for. |
116130

117131
```html+twig
118132
{{ content|ibexa_taxonomy_entries_for_content|map(entry => "#{entry.name}")|join(', ') }}
119133
```
120134

135+
```html+twig
136+
{{ product|ibexa_taxonomy_entries_for_content|map(entry => "#{entry.name}")|join(', ') }}
137+
```
121138

122139
## Non-content related queries
123140

docs/templating/twig_function_reference/field_twig_functions.md

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ The field is rendered with the default template, but you can optionally pass a d
3232

3333
| Argument | Type | Description |
3434
| ------ | ----- | ----- |
35-
| `content` | `Ibexa\Contracts\Core\Repository\Values\Content\Content` | Content item the field belongs to. |
35+
| `content` | [`Content`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-Content.html) or [`ContentAwareInterface`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-ContentAwareInterface.html) | Content item the field belongs to. |
3636
| `fieldDefinitionIdentifier` | `string` | Field identifier. |
3737
| `params` | `hash` | (optional) Hash of parameters passed to the template block. |
3838

@@ -48,6 +48,18 @@ The field is rendered with the default template, but you can optionally pass a d
4848
}) }}
4949
```
5050

51+
``` html+twig
52+
{{ ibexa_render_field(product, 'name') }}
53+
54+
{{ ibexa_render_field(product, 'image', {
55+
'template': '@ibexadesign/fields/image.html.twig',
56+
'attr': {class: 'thumbnail-image'},
57+
'parameters': {
58+
'alias': 'small'
59+
}
60+
}) }}
61+
```
62+
5163
#### Parameters
5264

5365
You can pass the following parameters to `ibexa_render_field()`:
@@ -80,14 +92,18 @@ If the content item doesn't have a translation in the prioritized or passed lang
8092

8193
| Argument | Type | Description |
8294
|-----|------|-----|
83-
| `content`| `Ibexa\Contracts\Core\Repository\Values\Content\Content` | Content item the field belongs to.|
95+
| `content` | [`Content`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-Content.html) or [`ContentAwareInterface`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-ContentAwareInterface.html) | Content item the field belongs to.|
8496
| `fieldDefIdentifier` | `string` | Identifier of the field. |
8597
| `forcedLanguage` | `string` | (optional) Language to use (for example, "fre-FR"). |
8698

8799
``` html+twig
88100
{{ ibexa_field_value(content, 'image') }}
89101
```
90102

103+
``` html+twig
104+
{{ ibexa_field_value(product, 'image') }}
105+
```
106+
91107
### `ibexa_field()`
92108

93109
`ibexa_field()` returns the field object.
@@ -96,7 +112,7 @@ If the content item doesn't have a translation in the prioritized or passed lang
96112

97113
| Argument | Type | Description |
98114
|-------|------|------|
99-
| `content`| `Ibexa\Contracts\Core\Repository\Values\Content\Content` | Content item the field belongs to.|
115+
| `content` | [`Content`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-Content.html) or [`ContentAwareInterface`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-ContentAwareInterface.html) | Content item the field belongs to.|
100116
| `fieldDefIdentifier` | `string` | Identifier of the field. |
101117
| `forcedLanguage` | `string` | {optional) Language to use (for example, "fre-FR"). |
102118

@@ -109,6 +125,10 @@ You can use `ibexa_field()` to access the field type identifier:
109125
{{ ibexa_field(content, 'my_field').fieldTypeIdentifier }}
110126
```
111127

128+
``` html+twig
129+
{{ ibexa_field(product, 'my_field').fieldTypeIdentifier }}
130+
```
131+
112132
## Field information
113133

114134
### `ibexa_field_name()`
@@ -120,7 +140,7 @@ If the content item doesn't have a translation in the prioritized or passed lang
120140

121141
| Argument | Type | Description |
122142
|---------------|------|-------------|
123-
| `content` | `Ibexa\Contracts\Core\Repository\Values\Content\Content` or `Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo` | Content item the field belongs to. |
143+
| `content` | [`Content`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-Content.html), [`ContentInfo`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-ContentInfo.html), or [`ContentAwareInterface`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-ContentAwareInterface.html) | Content item the field belongs to. |
124144
| `fieldDefIdentifier` | `string` | Identifier of the field. |
125145
| `forcedLanguage` | `string` | (optional) Language to use (for example, `fre-FR`). |
126146

@@ -131,6 +151,12 @@ If the content item doesn't have a translation in the prioritized or passed lang
131151
{{ ibexa_field_name(content, 'title', 'ger-DE') }}
132152
```
133153

154+
``` html+twig
155+
{{ ibexa_field_name(product, 'name') }}
156+
157+
{{ ibexa_field_name(product, 'name', 'pl-PL') }}
158+
```
159+
134160
### `ibexa_field_description()`
135161

136162
`ibexa_field_description()` returns the description of a content item's field.
@@ -140,7 +166,7 @@ If the content item doesn't have a translation in the prioritized or passed lang
140166

141167
| Argument | Type | Description |
142168
|---------------|------|-------------|
143-
| `content` | `Ibexa\Contracts\Core\Repository\Values\Content\Content` or `Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo` | Content item the field belongs to. |
169+
| `content` | [`Content`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-Content.html), [`ContentInfo`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-ContentInfo.html), or [`ContentAwareInterface`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-ContentAwareInterface.html) | Content item the field belongs to. |
144170
| `fieldDefIdentifier` | `string` | Identifier of the field. |
145171
| `forcedLanguage` | `string` | (optional) Language to use (for example, `fre-FR`). |
146172

@@ -150,20 +176,30 @@ If the content item doesn't have a translation in the prioritized or passed lang
150176
{{ ibexa_field_description(content, 'title', 'ger-DE') }}
151177
```
152178

179+
``` html+twig
180+
{{ ibexa_field_description(product, 'name') }}
181+
182+
{{ ibexa_field_description(product, 'name', 'fr-FR') }}
183+
```
184+
153185
### `ibexa_field_is_empty()`
154186

155187
`ibexa_field_is_empty()` returns Boolean information whether a given field of a content item is empty.
156188

157189
| Argument | Type | Description |
158190
|---------------|------|-------------|
159-
| `content` | `Ibexa\Contracts\Core\Repository\Values\Content\Content` or `Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo` | Content item the field belongs to. |
191+
| `content` | [`Content`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-Content.html) or [`ContentAwareInterface`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-ContentAwareInterface.html) | Content item the field belongs to. |
160192
| `fieldDefIdentifier` | `string` | Identifier of the field. |
161193
| `forcedLanguage` | `string` | (optional) Language to use (for example, `fre-FR`). |
162194

163195
``` html+twig
164196
{{ ibexa_field_is_empty(content, 'title') }}
165197
```
166198

199+
``` html+twig
200+
{{ ibexa_field_is_empty(product, 'name') }}
201+
```
202+
167203
#### Examples
168204

169205
For example, use `ibexa_field_is_empty()` to check whether a field is empty or filled before rendering it:
@@ -174,6 +210,12 @@ For example, use `ibexa_field_is_empty()` to check whether a field is empty or f
174210
{% endif %}
175211
```
176212

213+
``` html+twig
214+
{% if not ibexa_field_is_empty(product, 'image') %}
215+
{{ ibexa_render_field(product, 'image') }}
216+
{% endif %}
217+
```
218+
177219
### `ibexa_field_group_name()`
178220

179221
`ibexa_field_group_name()` returns a human-readable name of a field group.
@@ -193,11 +235,17 @@ For example, use `ibexa_field_is_empty()` to check whether a field is empty or f
193235

194236
| Argument | Type | Description |
195237
|---------------|------|-------------|
196-
| `content` | `Ibexa\Contracts\Core\Repository\Values\Content\Content` | Content item the field may belong to. |
238+
| `content` | [`Content`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-Content.html) or [`ContentAwareInterface`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-ContentAwareInterface.html) | Content item the field may belong to. |
197239
| `fieldDefIdentifier` | `string` | Identifier of the field. |
198240

199241
``` html+twig
200242
{% if ibexa_has_field(content, 'existing') %}
201243
{{ ibexa_render_field(content, 'existing') }}
202244
{% endif %}
245+
```
246+
247+
``` html+twig
248+
{% if ibexa_has_field(product, 'existing') %}
249+
{{ ibexa_render_field(product, 'existing') }}
250+
{% endif %}
203251
```

docs/templating/twig_function_reference/image_twig_functions.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ page_type: reference
1313
To render images, use the [`ibexa_render_field()`](field_twig_functions.md#ibexa_render_field) Twig function with the variation name passed as an argument, for example:
1414

1515
``` html+twig
16-
[[= include_file('docs/templating/twig_function_reference/field_twig_functions.md', 38, 45) =]]
16+
[[= include_file('docs/templating/twig_function_reference/field_twig_functions.md', 40, 48) =]]
1717
```
1818

1919
## Image information
@@ -48,12 +48,16 @@ To render images, use the [`ibexa_render_field()`](field_twig_functions.md#ibexa
4848

4949
| Argument | Type | Description |
5050
| ------ |----- | ----- |
51-
| `content` | `Ibexa\Contracts\Core\Repository\Values\Content\Content` | Content item to display the image for. |
51+
| `content` | [`Content`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-Content.html) or [`ContentAwareInterface`](../../api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-ContentAwareInterface.html) | Content item to display the image for. |
5252

5353
``` html+twig
5454
{% set firstImage = ibexa_content_field_identifier_first_filled_image(content) %}
5555
```
5656

57+
``` html+twig
58+
{% set firstImage = ibexa_content_field_identifier_first_filled_image(product) %}
59+
```
60+
5761
#### Examples
5862

5963
You can use `ibexa_content_field_identifier_first_filled_image()` to find and render the first existing image in an article:

0 commit comments

Comments
 (0)