Skip to content

Commit 81cc0cc

Browse files
committed
Adjusted code samples
1 parent 592b270 commit 81cc0cc

File tree

16 files changed

+83
-78
lines changed

16 files changed

+83
-78
lines changed

code_samples/api/public_php_api/src/Command/CreateContentTypeCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ class CreateContentTypeCommand extends Command
2626

2727
public function __construct(ContentTypeService $contentTypeService, UserService $userService, PermissionResolver $permissionResolver)
2828
{
29-
parent::__construct();
3029
$this->contentTypeService = $contentTypeService;
3130
$this->userService = $userService;
3231
$this->permissionResolver = $permissionResolver;
32+
33+
parent::__construct();
3334
}
3435

3536
protected function configure(): void

code_samples/api/public_php_api/src/Command/CreateImageCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@ class CreateImageCommand extends Command
3232

3333
public function __construct(ContentService $contentService, ContentTypeService $contentTypeService, LocationService $locationService, UserService $userService, PermissionResolver $permissionResolver)
3434
{
35-
parent::__construct();
3635
$this->contentService = $contentService;
3736
$this->contentTypeService = $contentTypeService;
3837
$this->locationService = $locationService;
3938
$this->userService = $userService;
4039
$this->permissionResolver = $permissionResolver;
40+
41+
parent::__construct();
4142
}
4243

4344
protected function configure(): void

code_samples/api/public_php_api/src/Command/DeleteContentCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ class DeleteContentCommand extends Command
2424

2525
public function __construct(LocationService $locationService, UserService $userService, PermissionResolver $permissionResolver)
2626
{
27-
parent::__construct();
2827
$this->locationService = $locationService;
2928
$this->userService = $userService;
3029
$this->permissionResolver = $permissionResolver;
30+
31+
parent::__construct();
3132
}
3233

3334
protected function configure(): void

code_samples/api/public_php_api/src/Command/FindComplexCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ class FindComplexCommand extends Command
2424

2525
public function __construct(SearchService $searchService, LocationService $locationService)
2626
{
27-
parent::__construct();
2827
$this->searchService = $searchService;
2928
$this->locationService = $locationService;
29+
30+
parent::__construct();
3031
}
3132

3233
protected function configure(): void

code_samples/api/public_php_api/src/Command/FindContentCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ class FindContentCommand extends Command
2020

2121
public function __construct(SearchService $searchService)
2222
{
23-
parent::__construct();
2423
$this->searchService = $searchService;
24+
25+
parent::__construct();
2526
}
2627

2728
protected function configure(): void

docs/api/php_api/php_api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ While [using `sudo()`](#using-sudo) is the recommended option, you can also set
126126
To identify as a different user, you need to use the `UserService` together with `PermissionResolver` (in the example `admin` is the login of the administrator user):
127127

128128
``` php
129-
[[= include_file('code_samples/api/public_php_api/src/Command/CreateContentCommand.php', 50, 52) =]]
129+
[[= include_file('code_samples/api/public_php_api/src/Command/CreateContentCommand.php', 55, 57) =]]
130130
```
131131

132132
!!! tip

docs/commerce/order_management/order_management_api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ To access a single order by using its string identifier, use the `OrderService::
2626
To access a single order by using its numerical ID, use the `OrderService::getOrder` method:
2727

2828
``` php
29-
[[= include_file('code_samples/api/commerce/src/Command/OrderCommand.php', 68, 72) =]]
29+
[[= include_file('code_samples/api/commerce/src/Command/OrderCommand.php', 67, 72) =]]
3030
```
3131

3232
## Get multiple orders

docs/content_management/content_api/browsing_content.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ This value object provides primitive fields, such as `contentTypeId`, `published
2525

2626
You can also use it to request other Content-related value objects from various services:
2727

28-
``` php hl_lines="9"
28+
``` php hl_lines="10"
2929
// ...
3030
[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 4, 5) =]]
31-
[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 20, 21) =]]
31+
[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 20, 22) =]]
3232
// ...
33-
[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 55, 57) =]][[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 63, 64) =]]
34-
[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 65, 71) =]]
33+
[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 55, 57) =]][[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 63, 72) =]]
3534
```
3635

36+
3737
`ContentInfo` is loaded from the [`ContentService`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-ContentService.html) (line 9).
3838
It provides you with basic content metadata such as modification and publication dates or main language code.
3939

@@ -142,7 +142,7 @@ You need to provide it with the object state group.
142142
All object state groups can be retrieved through [`loadObjectStateGroups`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-ObjectStateService.html#method_loadObjectStateGroups).
143143

144144
``` php
145-
[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 115, 120) =]]
145+
[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 120, 125) =]]
146146
```
147147

148148
## Viewing content with fields
@@ -151,7 +151,7 @@ To retrieve the fields of the selected content item, you can use the following c
151151

152152
```php hl_lines="13-14 16-22"
153153
[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentCommand.php', 4, 7) =]] // ...
154-
[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentCommand.php', 37, 55) =]]
154+
[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentCommand.php', 42, 60) =]]
155155
}
156156
```
157157

@@ -182,7 +182,7 @@ $contentService->loadContent($content->id, Language::ALL);
182182
To go through all the content items contained in a subtree, you need to use the [`LocationService`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-LocationService.html).
183183

184184
``` php hl_lines="5 15"
185-
[[= include_file('code_samples/api/public_php_api/src/Command/BrowseLocationsCommand.php', 30, 49) =]]
185+
[[= include_file('code_samples/api/public_php_api/src/Command/BrowseLocationsCommand.php', 35, 54) =]]
186186
```
187187

188188
`loadLocation` (line 15) returns a value object, here a `Location`.

docs/content_management/content_api/creating_content.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Value objects such as content items are read-only, so to create or modify them y
2121
returns a new [`ContentCreateStruct`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-ContentCreateStruct.html) object.
2222

2323
``` php hl_lines="2-3 5"
24-
[[= include_file('code_samples/api/public_php_api/src/Command/CreateContentCommand.php', 57, 66) =]]
24+
[[= include_file('code_samples/api/public_php_api/src/Command/CreateContentCommand.php', 62, 71) =]]
2525
```
2626

2727
This command creates a draft using [`ContentService::createContent`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-ContentService.html#method_createContent) (line 7).
@@ -42,7 +42,7 @@ Therefore, when creating a content item of the Image type (or any other content
4242
the `ContentCreateStruct` is slightly more complex than in the previous example:
4343

4444
``` php
45-
[[= include_file('code_samples/api/public_php_api/src/Command/CreateImageCommand.php', 56, 69) =]]
45+
[[= include_file('code_samples/api/public_php_api/src/Command/CreateImageCommand.php', 61, 74) =]]
4646
```
4747

4848
Value of the Image field type contains the path to the image file and other basic information based on the input file.
@@ -66,7 +66,7 @@ To publish it, use [`ContentService::publishVersion`](/api/php_api/php_api_refer
6666
This method must get the [`VersionInfo`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-VersionInfo.html) object of a draft version.
6767

6868
``` php
69-
[[= include_file('code_samples/api/public_php_api/src/Command/CreateContentCommand.php', 68, 69) =]]
69+
[[= include_file('code_samples/api/public_php_api/src/Command/CreateContentCommand.php', 73, 74) =]]
7070
```
7171

7272
## Updating content
@@ -76,7 +76,7 @@ and pass it to [`ContentService::updateContent`](/api/php_api/php_api_reference/
7676
This method works on a draft, so to publish your changes you need to use [`ContentService::publishVersion`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-ContentService.html#method_publishVersion) as well:
7777

7878
``` php
79-
[[= include_file('code_samples/api/public_php_api/src/Command/UpdateContentCommand.php', 47, 55) =]]
79+
[[= include_file('code_samples/api/public_php_api/src/Command/UpdateContentCommand.php', 52, 60) =]]
8080
```
8181

8282
## Translating content
@@ -86,15 +86,15 @@ Content [translations](languages.md#language-versions) are created per version.
8686
To translate a content item to a new language, you need to update it and provide a new `initialLanguageCode`:
8787

8888
``` php
89-
[[= include_file('code_samples/api/public_php_api/src/Command/TranslateContentCommand.php', 52, 57) =]]
90-
[[= include_file('code_samples/api/public_php_api/src/Command/TranslateContentCommand.php', 62, 64) =]]
89+
[[= include_file('code_samples/api/public_php_api/src/Command/TranslateContentCommand.php', 57, 62) =]]
90+
[[= include_file('code_samples/api/public_php_api/src/Command/TranslateContentCommand.php', 67, 69) =]]
9191
```
9292

9393
You can also update content in multiple languages at once using the `setField` method's third argument.
9494
Only one language can still be set as a version's initial language:
9595

9696
``` php
97-
[[= include_file('code_samples/api/public_php_api/src/Command/TranslateContentCommand.php', 59, 60) =]]
97+
[[= include_file('code_samples/api/public_php_api/src/Command/TranslateContentCommand.php', 64, 65) =]]
9898
```
9999

100100
### Deleting a translation

docs/content_management/content_api/managing_content.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ Creating a new location, like creating content, requires using a struct, because
2222
To add a new location to existing content you need to create a [`LocationCreateStruct`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-LocationCreateStruct.html) and pass it to the [`LocationService::createLocation`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-LocationService.html#method_createLocation) method:
2323

2424
``` php
25-
[[= include_file('code_samples/api/public_php_api/src/Command/AddLocationToContentCommand.php', 50, 51) =]]
26-
[[= include_file('code_samples/api/public_php_api/src/Command/AddLocationToContentCommand.php', 55, 57) =]]
25+
[[= include_file('code_samples/api/public_php_api/src/Command/AddLocationToContentCommand.php', 55, 56) =]]
26+
[[= include_file('code_samples/api/public_php_api/src/Command/AddLocationToContentCommand.php', 60, 62) =]]
2727
```
2828

2929
`LocationCreateStruct` must receive the parent location ID.
@@ -32,7 +32,7 @@ It sets the `parentLocationId` property of the new location.
3232
You can also provide other properties for the location, otherwise they're set to their defaults:
3333

3434
``` php
35-
[[= include_file('code_samples/api/public_php_api/src/Command/AddLocationToContentCommand.php', 52, 54) =]]
35+
[[= include_file('code_samples/api/public_php_api/src/Command/AddLocationToContentCommand.php', 57, 59) =]]
3636
```
3737

3838
### Changing the main location
@@ -41,15 +41,15 @@ When a content item has more that one location, one location is always considere
4141
You can change the main location using [`ContentService`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-ContentService.html), by updating the `ContentInfo` with a [`ContentUpdateStruct`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-ContentUpdateStruct.html) that sets the new main location:
4242

4343
``` php
44-
[[= include_file('code_samples/api/public_php_api/src/Command/SetMainLocationCommand.php', 48, 52) =]]
44+
[[= include_file('code_samples/api/public_php_api/src/Command/SetMainLocationCommand.php', 53, 57) =]]
4545
```
4646

4747
### Hiding and revealing locations
4848

4949
To hide or reveal (unhide) a location you need to make use of [`LocationService::hideLocation`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-LocationService.html#method_hideLocation) or [`LocationService::unhideLocation`:](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-LocationService.html#method_unhideLocation)
5050

5151
``` php
52-
[[= include_file('code_samples/api/public_php_api/src/Command/HideLocationCommand.php', 46, 47) =]][[= include_file('code_samples/api/public_php_api/src/Command/HideLocationCommand.php', 49, 50) =]]
52+
[[= include_file('code_samples/api/public_php_api/src/Command/HideLocationCommand.php', 51, 52) =]][[= include_file('code_samples/api/public_php_api/src/Command/HideLocationCommand.php', 54, 55) =]]
5353
```
5454

5555
See [location visibility](locations.md#location-visibility) for detailed information on the behavior of visible and hidden Locations.
@@ -66,22 +66,22 @@ Content which has more locations is still available in its other locations.
6666
If you delete the [main location](#changing-the-main-location) of a content item that has more locations, another location becomes the main one.
6767

6868
``` php
69-
[[= include_file('code_samples/api/public_php_api/src/Command/DeleteContentCommand.php', 44, 45) =]]
69+
[[= include_file('code_samples/api/public_php_api/src/Command/DeleteContentCommand.php', 49, 50) =]]
7070
```
7171

7272
To send the location and its subtree to Trash, use [`TrashService::trash`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-TrashService.html#).
7373
Items in Trash can be later [restored, or deleted permanently](#trash).
7474

7575
``` php
76-
[[= include_file('code_samples/api/public_php_api/src/Command/TrashContentCommand.php', 54, 55) =]]
76+
[[= include_file('code_samples/api/public_php_api/src/Command/TrashContentCommand.php', 59, 60) =]]
7777
```
7878

7979
### Moving and copying a subtree
8080

8181
You can move a location with its whole subtree using [`LocationService::moveSubtree`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-LocationService.html#method_moveSubtree):
8282

8383
``` php
84-
[[= include_file('code_samples/api/public_php_api/src/Command/MoveContentCommand.php', 46, 49) =]]
84+
[[= include_file('code_samples/api/public_php_api/src/Command/MoveContentCommand.php', 51, 54) =]]
8585
```
8686

8787
[`LocationService::copySubtree`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-LocationService.html#method_copySubtree) is used in the same way, but it copies the location and its subtree instead of moving it.
@@ -108,7 +108,7 @@ You must provide the method with the ID of the object in Trash.
108108
Trash location is identical to the origin location of the object.
109109

110110
``` php
111-
[[= include_file('code_samples/api/public_php_api/src/Command/TrashContentCommand.php', 64, 65) =]]
111+
[[= include_file('code_samples/api/public_php_api/src/Command/TrashContentCommand.php', 69, 70) =]]
112112
```
113113

114114
The content item is restored under its previous location.
@@ -138,29 +138,29 @@ In this case you use [`ContentTypeCreateStruct`](/api/php_api/php_api_reference/
138138
A content type must have at least one name, in the main language, and at least one field definition.
139139

140140
``` php
141-
[[= include_file('code_samples/api/public_php_api/src/Command/CreateContentTypeCommand.php', 59, 69) =]][[= include_file('code_samples/api/public_php_api/src/Command/CreateContentTypeCommand.php', 76, 85) =]]
141+
[[= include_file('code_samples/api/public_php_api/src/Command/CreateContentTypeCommand.php', 64, 74) =]][[= include_file('code_samples/api/public_php_api/src/Command/CreateContentTypeCommand.php', 81, 90) =]]
142142
```
143143

144144
You can specify more details of the field definition in the create struct, for example:
145145

146146
``` php
147-
[[= include_file('code_samples/api/public_php_api/src/Command/CreateContentTypeCommand.php', 67, 77) =]]
147+
[[= include_file('code_samples/api/public_php_api/src/Command/CreateContentTypeCommand.php', 72, 82) =]]
148148
```
149149

150150
### Copying content types
151151

152152
To copy a content type, use [`ContentTypeService::copyContentType`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-ContentTypeService.html#method_copyContentType):
153153

154154
``` php
155-
[[= include_file('code_samples/api/public_php_api/src/Command/CreateContentTypeCommand.php', 89, 90) =]]
155+
[[= include_file('code_samples/api/public_php_api/src/Command/CreateContentTypeCommand.php', 94, 95) =]]
156156
```
157157

158158
The copy is automatically getting an identifier based on the original content type identifier and the copy's ID, for example: `copy_of_folder_21`.
159159

160160
To change the identifier of the copy, use a [`ContentTypeUpdateStruct`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-ContentType-ContentTypeUpdateStruct.html):
161161

162162
``` php
163-
[[= include_file('code_samples/api/public_php_api/src/Command/CreateContentTypeCommand.php', 90, 96) =]]
163+
[[= include_file('code_samples/api/public_php_api/src/Command/CreateContentTypeCommand.php', 95, 101) =]]
164164
```
165165

166166
## Calendar events
@@ -177,19 +177,19 @@ To get a list of events for a specified time period, use the `CalendarServiceInt
177177
You need to provide the method with an EventQuery, which takes a date range and a count as the minimum of parameters:
178178

179179
``` php
180-
[[= include_file('code_samples/api/public_php_api/src/Command/CalendarCommand.php', 39, 50) =]]
180+
[[= include_file('code_samples/api/public_php_api/src/Command/CalendarCommand.php', 44, 55) =]]
181181
```
182182

183183
You can also get the first and last event in the list by using the `first()` and `last()` methods of an `EventCollection` (`Ibexa\Contracts\Calendar\EventCollection`):
184184

185185
``` php
186-
[[= include_file('code_samples/api/public_php_api/src/Command/CalendarCommand.php', 51, 53) =]]
186+
[[= include_file('code_samples/api/public_php_api/src/Command/CalendarCommand.php', 56, 58) =]]
187187
```
188188

189189
You can process the events in a collection using the `find(Closure $predicate)`, `filter(Closure $predicate)`, `map(Closure $callback)` or `slice(int $offset, ?int $length = null)` methods of `EventCollection`, for example:
190190

191191
``` php
192-
[[= include_file('code_samples/api/public_php_api/src/Command/CalendarCommand.php', 54, 57) =]]
192+
[[= include_file('code_samples/api/public_php_api/src/Command/CalendarCommand.php', 59, 62) =]]
193193
```
194194

195195
### Performing calendar actions
@@ -199,7 +199,7 @@ You must pass an `Ibexa\Contracts\Calendar\EventAction\EventActionContext` insta
199199
`EventActionContext` defines events on which the action is performed, and action-specific parameters, for example, a new date:
200200

201201
``` php
202-
[[= include_file('code_samples/api/public_php_api/src/Command/CalendarCommand.php', 59, 61) =]]
202+
[[= include_file('code_samples/api/public_php_api/src/Command/CalendarCommand.php', 64, 66) =]]
203203
```
204204

205205
``` php

0 commit comments

Comments
 (0)