-
Notifications
You must be signed in to change notification settings - Fork 82
IBX-10885: Document Content Type search API #2946
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 5.0
Are you sure you want to change the base?
Changes from all commits
5c12311
f80b676
a0a000d
c7fd369
d1af1b0
6d1f207
0269c3a
86eaee1
6383d26
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| <?php declare(strict_types=1); | ||
|
|
||
| namespace App\Command; | ||
|
|
||
| use Ibexa\Contracts\Core\Repository\ContentTypeService; | ||
| use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\ContentTypeQuery; | ||
| use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\Criterion; | ||
| use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\SortClause; | ||
| use Symfony\Component\Console\Attribute\AsCommand; | ||
| use Symfony\Component\Console\Command\Command; | ||
| use Symfony\Component\Console\Input\InputInterface; | ||
| use Symfony\Component\Console\Output\OutputInterface; | ||
|
|
||
| #[AsCommand( | ||
| name: 'doc:find_content_types', | ||
| description: 'Lists content types that match specific criteria.' | ||
| )] | ||
| class FindContentTypeCommand extends Command | ||
| { | ||
| public function __construct(private readonly ContentTypeService $contentTypeService) | ||
| { | ||
| parent::__construct(); | ||
| } | ||
|
|
||
| protected function execute(InputInterface $input, OutputInterface $output): int | ||
| { | ||
| // Find content types from the "Content" group that contains a specific field definition (in this case, a "Body" field). | ||
| $query = new ContentTypeQuery( | ||
| new Criterion\LogicalAnd([ | ||
| new Criterion\ContentTypeGroupId([1]), | ||
| new Criterion\ContainsFieldDefinitionId([121]), | ||
| ]), | ||
| [ | ||
| new SortClause\Id(), | ||
| new SortClause\Identifier(), | ||
| new SortClause\Name(), | ||
| ] | ||
| ); | ||
|
|
||
| $searchResult = $this->contentTypeService->findContentTypes($query); | ||
|
|
||
| $output->writeln('Found ' . $searchResult->getTotalCount() . ' content type(s):'); | ||
|
|
||
| foreach ($searchResult->getContentTypes() as $contentType) { | ||
| $output->writeln(sprintf( | ||
| '- [%d] %s (identifier: %s)', | ||
| $contentType->id, | ||
| $contentType->getName(), | ||
| $contentType->identifier | ||
| )); | ||
| } | ||
|
|
||
| return Command::SUCCESS; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| --- | ||
|
Check warning on line 1 in docs/search/content_type_search_reference/content_type_criteria.md
|
||
| 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`)](managing_content.md#finding-and-filtering-content-types). | ||
|
|
||
| | 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. | | ||
|
Check failure on line 13 in docs/search/content_type_search_reference/content_type_criteria.md
|
||
| | [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. | | ||
|
Check failure on line 14 in docs/search/content_type_search_reference/content_type_criteria.md
|
||
| | [ContentTypeId](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-ContentType-Query-Criterion-ContentTypeId.html) | Matches content types by their ID. | | ||
|
Check failure on line 15 in docs/search/content_type_search_reference/content_type_criteria.md
|
||
| | [ContentTypeIdentifier](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-ContentType-Query-Criterion-ContentTypeIdentifier.html) | Matches content types by their identifier. | | ||
|
Check failure on line 16 in docs/search/content_type_search_reference/content_type_criteria.md
|
||
| | [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. | | ||
|
Check failure on line 17 in docs/search/content_type_search_reference/content_type_criteria.md
|
||
| | [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. | | ||
|
Check failure on line 18 in docs/search/content_type_search_reference/content_type_criteria.md
|
||
| | [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. | | ||
|
Check failure on line 19 in docs/search/content_type_search_reference/content_type_criteria.md
|
||
| | [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. | | ||
|
Check failure on line 20 in docs/search/content_type_search_reference/content_type_criteria.md
|
||
|
|
||
| The following example shows how to use them to search for content types: | ||
|
|
||
| ```php hl_lines="29-31" | ||
| [[= include_file('code_samples/api/public_php_api/src/Command/FindContentTypeCommand.php') =]] | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| --- | ||
|
Check warning on line 1 in docs/search/content_type_search_reference/content_type_sort_clauses.md
|
||
| 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/namespaces/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 | | ||
|
Check failure on line 15 in docs/search/content_type_search_reference/content_type_sort_clauses.md
|
||
| | [Identifier](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-ContentType-Query-SortClause-Identifier.html)| Sort by content type's identifier | | ||
|
Check failure on line 16 in docs/search/content_type_search_reference/content_type_sort_clauses.md
|
||
| | [Name](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-ContentType-Query-SortClause-Name.html)| Sort by content type's name | | ||
|
Check failure on line 17 in docs/search/content_type_search_reference/content_type_sort_clauses.md
|
||
|
|
||
|
|
||
| The following example shows how to use them to sort the searched content types: | ||
|
|
||
| ```php hl_lines="34-36" | ||
| [[= 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). | ||
|
Check failure on line 26 in docs/search/content_type_search_reference/content_type_sort_clauses.md
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Friendly reminder that this will not work on 4.6 - and needs to be downgraded (I can help with that if needed).
In general it's easier to write code for 4.6 and then update it to v5 with Rector - we don't have Rector downgrades configured (if they are doable at all)