Skip to content

Commit 02adaec

Browse files
committed
IBX-10885: Document Content Type search API
1 parent f154d3c commit 02adaec

File tree

4 files changed

+125
-0
lines changed

4 files changed

+125
-0
lines changed

docs/content_management/content_api/managing_content.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,58 @@ To change the identifier of the copy, use a [`ContentTypeUpdateStruct`](/api/php
165165
[[= include_file('code_samples/api/public_php_api/src/Command/CreateContentTypeCommand.php', 87, 93) =]]
166166
```
167167

168+
### Finding and filtering content types
169+
170+
You can find content types that match specific criteria by using the `ContentTypeService::findContentTypes()` method.
171+
This method accepts a `ContentTypeQuery` object that supports filtering and sorting by IDs, identifiers, group membership, and other criteria.
172+
173+
!!! note "Criterions and sort clauses"
174+
175+
For a full list of available criterions and sort clauses that you can use when finding and filtering content types, see [Content Type Search Criteria](content_type_criteria.md) and [Content Type Search Sort Clauses](content_type_sort_clauses.md) references.
176+
177+
178+
The following example shows how you can use the criteria to find content types:
179+
180+
```php hl_lines="9-15"
181+
<?php
182+
183+
declare(strict_types=1);
184+
185+
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\Criterion;
186+
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\ContentTypeQuery;
187+
188+
// Example: find content types whose identifier is "folder" or "article" *and* are in group 1, or identifier is "user":
189+
$query = new ContentTypeQuery(
190+
new Criterion\LogicalOr([
191+
new Criterion\LogicalAnd([
192+
new Criterion\ContentTypeIdentifier(['folder','article']),
193+
new Criterion\ContentTypeGroupIds([1]),
194+
]),
195+
new Criterion\ContentTypeIdentifier(['user']),
196+
]),
197+
[
198+
new SortClause\Id(),
199+
new SortClause\Identifier(),
200+
new SortClause\Name(),
201+
]
202+
);
203+
204+
$results = $contentTypeService->findContentTypes($query);
205+
```
206+
207+
#### Query parameters
208+
209+
When constructing a `ContentTypeQuery`, you can pass the following parameters:
210+
211+
- `?CriterionInterface $criterion = null` — a filter to apply (use one or a combination of the criterions above)
212+
213+
- `array $sortClauses = []` — list of sort clauses to order the results
214+
215+
- `int $offset = 0` — starting offset (for pagination)
216+
217+
- `int $limit = 25` — maximum number of results to return
218+
219+
168220
## Calendar events
169221

170222
You can handle the calendar using `CalendarServiceInterface` (`Ibexa\Contracts\Calendar\CalendarServiceInterface`).
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
description: Content Type Search Criteria help define and fine-tune search queries for content types.
3+
page_type: reference
4+
month_change: true
5+
---
6+
7+
# Content Type Search Criteria reference
8+
9+
Content Type Search Criteria are only supported by Content Type Search (`ContentTypeService::findContentTypes`).
10+
11+
| Criterion | Description |
12+
|-------|-------------|
13+
| [ContainsFieldDefinitionId](api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-ContentType-Query-Criterion-ContainsFieldDefinitionId.html) | Matches content types that contain a field definition with the specified ID. |
14+
| [ContentTypeGroupId](api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-ContentType-Query-Criterion-ContentTypeGroupId.html) | Matches content types by their assigned group ID. |
15+
| [ContentTypeId](api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-ContentType-Query-Criterion-ContentTypeId.html) | Matches content types by their ID. |
16+
| [ContentTypeIdentifier](api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-ContentType-Query-Criterion-ContentTypeIdentifier.html) | Matches content types by their identifier. |
17+
| [IsSystem](api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-ContentType-Query-Criterion-IsSystem.html) | Matches content types based on whether the group they belong to is system or not. |
18+
| [LogicalAnd](api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-ContentType-Query-Criterion-LogicalAnd.html) | Implements a logical AND Criterion. It matches if ALL of the provided Criteria match. |
19+
| [LogicalOr](api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-ContentType-Query-Criterion-LogicalOr.html) | Implements a logical OR Criterion. It matches if at least one of the provided Criteria matches. |
20+
| [LogicalNot](api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-ContentType-Query-Criterion-LogicalNot.html) | Implements a logical NOT Criterion. It matches if the provided Criterion doesn't match. |
21+
22+
For an example that shows how you can use the criteria to find content types, see [Finding and filtering content types](managing_content.md#finding-and-filtering-content-types).
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
description: Content Type Search Sort Clauses
3+
month_change: true
4+
---
5+
6+
# Content Type Search Sort Clauses
7+
8+
Content Type Search Sort Clauses are the sorting options for content types.
9+
They're only supported by [Content Type Search (`ContentTypeService::findContentTypes`)](managing_content.md#finding-and-filtering-content-types).
10+
11+
Sort Clauses are found in the [`Ibexa\Contracts\Core\Repository\Values\ContentType\Query\SortClause`](api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-ContentType-Query-SortClause.html) namespace:
12+
13+
| Name | Description |
14+
| --- | --- |
15+
| [Id](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-ContentType-Query-SortClause-Id.html)| Sort by content type's id |
16+
| [Identifier](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-ContentType-Query-SortClause-Identifier.html)| Sort by content type's identifier |
17+
| [Name](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-ContentType-Query-SortClause-Name.html)| Sort by content type's name |
18+
19+
20+
The following example shows how to use them to sort the searched content items:
21+
22+
```php hl_lines="18-20"
23+
<?php
24+
25+
declare(strict_types=1);
26+
27+
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\Criterion;
28+
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\ContentTypeQuery;
29+
30+
// Example: find content types whose identifier is "folder" or "article" *and* are in group 1, or identifier is "user":
31+
$query = new ContentTypeQuery(
32+
new Criterion\LogicalOr([
33+
new Criterion\LogicalAnd([
34+
new Criterion\ContentTypeIdentifier(['folder','article']),
35+
new Criterion\ContentTypeGroupIds([1]),
36+
]),
37+
new Criterion\ContentTypeIdentifier(['user']),
38+
]),
39+
[
40+
new SortClause\Id(),
41+
new SortClause\Identifier(),
42+
new SortClause\Name(),
43+
]
44+
);
45+
46+
$results = $contentTypeService->findContentTypes($query);
47+
```
48+
49+
You can change the default sorting order by using the `SORT_ASC` and `SORT_DESC` constants from [`AbstractSortClause`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-CoreSearch-Values-Query-AbstractSortClause.html#constants).

mkdocs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@ nav:
566566
- LogicalAnd Criterion: search/criteria_reference/logicaland_criterion.md
567567
- LogicalNot Criterion: search/criteria_reference/logicalnot_criterion.md
568568
- LogicalOr Criterion: search/criteria_reference/logicalor_criterion.md
569+
- Content Type Search Criteria: search/content_type_search_reference/content_type_criteria.md
569570
- Product Search Criteria:
570571
- Product Search Criteria: search/criteria_reference/product_search_criteria.md
571572
- AttributeName: search/criteria_reference/attributename_criterion.md
@@ -705,6 +706,7 @@ nav:
705706
- SectionName: search/sort_clause_reference/sectionname_sort_clause.md
706707
- UserLogin: search/sort_clause_reference/userlogin_sort_clause.md
707708
- Visibility: search/sort_clause_reference/visibility_sort_clause.md
709+
- Content Type Sort Clauses: search/content_type_search_reference/content_type_sort_clauses.md
708710
- Product Sort Clauses:
709711
- Product Sort Clauses: search/sort_clause_reference/product_sort_clauses.md
710712
- BasePrice: search/sort_clause_reference/baseprice_sort_clause.md

0 commit comments

Comments
 (0)