- Documentation >
- Search >
- Content Type Search Criteria
Content Type Search Criteria reference
Content Type Search Criteria are only supported by Content Type Search (ContentTypeService::findContentTypes).
| Criterion |
Description |
| ContainsFieldDefinitionId |
Matches content types that contain a field definition with the specified ID. |
| ContentTypeGroupId |
Matches content types by their assigned group ID. |
| ContentTypeGroupName |
Matches content types by the name of their assigned group. |
| ContentTypeId |
Matches content types by their ID. |
| ContentTypeIdentifier |
Matches content types by their identifier. |
| IsSystem |
Matches content types based on whether the group they belong to is system or not. |
| LogicalAnd |
Implements a logical AND Criterion. It matches if ALL of the provided Criteria match. |
| LogicalOr |
Implements a logical OR Criterion. It matches if at least one of the provided Criteria matches. |
| LogicalNot |
Implements a logical NOT Criterion. It matches if the provided Criterion doesn't match. |
The following example shows how to use them to search for content types:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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\ContentTypeGroupName(['Content']),
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;
}
}
|