diff --git a/code_samples/api/public_php_api/src/Command/FindContentTypeCommand.php b/code_samples/api/public_php_api/src/Command/FindContentTypeCommand.php new file mode 100644 index 0000000000..32255e7dc1 --- /dev/null +++ b/code_samples/api/public_php_api/src/Command/FindContentTypeCommand.php @@ -0,0 +1,59 @@ +contentTypeService->findContentTypes($query); + + $output->writeln('Found ' . $searchResult->totalCount . ' content types:'); + + foreach ($searchResult->searchHits as $searchHit) { + $contentType = $searchHit->valueObject; + $output->writeln(sprintf( + '- [%d] %s (identifier: %s)', + $contentType->id, + $contentType->getName(), + $contentType->identifier + )); + } + + return Command::SUCCESS; + } +} diff --git a/docs/content_management/content_api/managing_content.md b/docs/content_management/content_api/managing_content.md index 827da71f16..0e855e9067 100644 --- a/docs/content_management/content_api/managing_content.md +++ b/docs/content_management/content_api/managing_content.md @@ -165,6 +165,35 @@ To change the identifier of the copy, use a [`ContentTypeUpdateStruct`](/api/php [[= include_file('code_samples/api/public_php_api/src/Command/CreateContentTypeCommand.php', 87, 93) =]] ``` +### Finding and filtering content types + +You can find content types that match specific criteria by using the `ContentTypeService::findContentTypes()` method. +This method accepts a `ContentTypeQuery` object that supports filtering and sorting by IDs, identifiers, group membership, and other criteria. + +!!! note "Criterions and sort clauses" + + 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. + + +The following example shows how you can use the criteria to find content types: + +```php hl_lines="12-17" +[[= include_file('code_samples/api/public_php_api/src/Command/FindContentTypeCommand.php', 17, 43) =]] +``` + +#### Query parameters + +When constructing a `ContentTypeQuery`, you can pass the following parameters: + +- `?CriterionInterface $criterion = null` — a filter to apply (use one or a combination of the criterions above) + +- `array $sortClauses = []` — list of sort clauses to order the results + +- `int $offset = 0` — starting offset (for pagination) + +- `int $limit = 25` — maximum number of results to return + + ## Calendar events You can handle the calendar using `CalendarServiceInterface` (`Ibexa\Contracts\Calendar\CalendarServiceInterface`). diff --git a/docs/search/content_type_search_reference/content_type_criteria.md b/docs/search/content_type_search_reference/content_type_criteria.md new file mode 100644 index 0000000000..96013f648c --- /dev/null +++ b/docs/search/content_type_search_reference/content_type_criteria.md @@ -0,0 +1,22 @@ +--- +description: Content Type Search Criteria help define and fine-tune search queries for content types. +page_type: reference +month_change: true +--- + +# Content Type Search Criteria reference + +Content Type Search Criteria are only supported by Content Type Search (`ContentTypeService::findContentTypes`). + +| Criterion | Description | +|-------|-------------| +| [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. | +| [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. | +| [ContentTypeId](api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-ContentType-Query-Criterion-ContentTypeId.html) | Matches content types by their ID. | +| [ContentTypeIdentifier](api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-ContentType-Query-Criterion-ContentTypeIdentifier.html) | Matches content types by their identifier. | +| [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. | +| [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. | +| [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. | +| [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. | + +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). diff --git a/docs/search/content_type_search_reference/content_type_sort_clauses.md b/docs/search/content_type_search_reference/content_type_sort_clauses.md new file mode 100644 index 0000000000..6f54d4efc5 --- /dev/null +++ b/docs/search/content_type_search_reference/content_type_sort_clauses.md @@ -0,0 +1,26 @@ +--- +description: Content Type Search Sort Clauses +month_change: true +--- + +# Content Type Search Sort Clauses + +Content Type Search Sort Clauses are the sorting options for content types. +They're only supported by [Content Type Search (`ContentTypeService::findContentTypes`)](managing_content.md#finding-and-filtering-content-types). + +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: + +| Name | Description | +| --- | --- | +| [Id](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-ContentType-Query-SortClause-Id.html)| Sort by content type's id | +| [Identifier](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-ContentType-Query-SortClause-Identifier.html)| Sort by content type's identifier | +| [Name](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-ContentType-Query-SortClause-Name.html)| Sort by content type's name | + + +The following example shows how to use them to sort the searched content items: + +```php hl_lines="37-39" +[[= include_file('code_samples/api/public_php_api/src/Command/FindContentTypeCommand.php') =]] +``` + +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). diff --git a/mkdocs.yml b/mkdocs.yml index b9deb0e76a..4ab999904c 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -566,6 +566,7 @@ nav: - LogicalAnd Criterion: search/criteria_reference/logicaland_criterion.md - LogicalNot Criterion: search/criteria_reference/logicalnot_criterion.md - LogicalOr Criterion: search/criteria_reference/logicalor_criterion.md + - Content Type Search Criteria: search/content_type_search_reference/content_type_criteria.md - Product Search Criteria: - Product Search Criteria: search/criteria_reference/product_search_criteria.md - AttributeName: search/criteria_reference/attributename_criterion.md @@ -705,6 +706,7 @@ nav: - SectionName: search/sort_clause_reference/sectionname_sort_clause.md - UserLogin: search/sort_clause_reference/userlogin_sort_clause.md - Visibility: search/sort_clause_reference/visibility_sort_clause.md + - Content Type Sort Clauses: search/content_type_search_reference/content_type_sort_clauses.md - Product Sort Clauses: - Product Sort Clauses: search/sort_clause_reference/product_sort_clauses.md - BasePrice: search/sort_clause_reference/baseprice_sort_clause.md