|
| 1 | +<?php declare(strict_types=1); |
| 2 | + |
| 3 | +namespace App\Command; |
| 4 | + |
| 5 | +use Ibexa\Contracts\Core\Repository\ContentTypeService; |
| 6 | +use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\ContentTypeQuery; |
| 7 | +use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\Criterion; |
| 8 | +use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\SortClause; |
| 9 | +use Symfony\Component\Console\Attribute\AsCommand; |
| 10 | +use Symfony\Component\Console\Command\Command; |
| 11 | +use Symfony\Component\Console\Input\InputInterface; |
| 12 | +use Symfony\Component\Console\Output\OutputInterface; |
| 13 | + |
| 14 | +#[AsCommand( |
| 15 | + name: 'doc:find_content_types', |
| 16 | + description: 'Lists content types that match specific criteria.' |
| 17 | +)] |
| 18 | +class FindContentTypeCommand extends Command |
| 19 | +{ |
| 20 | + public function __construct(private readonly ContentTypeService $contentTypeService) |
| 21 | + { |
| 22 | + parent::__construct(); |
| 23 | + } |
| 24 | + |
| 25 | + protected function execute(InputInterface $input, OutputInterface $output): int |
| 26 | + { |
| 27 | + // Find content types from the "Content" group that contains a specific field definition (in this case, a "Body" field). |
| 28 | + $query = new ContentTypeQuery( |
| 29 | + new Criterion\LogicalAnd([ |
| 30 | + new Criterion\ContentTypeGroupId([1]), |
| 31 | + new Criterion\ContainsFieldDefinitionId([121]), |
| 32 | + ]), |
| 33 | + [ |
| 34 | + new SortClause\Id(), |
| 35 | + new SortClause\Identifier(), |
| 36 | + new SortClause\Name(), |
| 37 | + ] |
| 38 | + ); |
| 39 | + |
| 40 | + $searchResult = $this->contentTypeService->findContentTypes($query); |
| 41 | + |
| 42 | + $output->writeln('Found ' . $searchResult->getTotalCount() . ' content type(s):'); |
| 43 | + |
| 44 | + foreach ($searchResult->getContentTypes() as $contentType) { |
| 45 | + $output->writeln(sprintf( |
| 46 | + '- [%d] %s (identifier: %s)', |
| 47 | + $contentType->id, |
| 48 | + $contentType->getName(), |
| 49 | + $contentType->identifier |
| 50 | + )); |
| 51 | + } |
| 52 | + |
| 53 | + return Command::SUCCESS; |
| 54 | + } |
| 55 | +} |
0 commit comments