-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathViewContentCommand.php
More file actions
61 lines (49 loc) · 2.1 KB
/
Copy pathViewContentCommand.php
File metadata and controls
61 lines (49 loc) · 2.1 KB
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
56
57
58
59
60
61
<?php declare(strict_types=1);
namespace App\Command;
use Ibexa\Contracts\Core\Repository\ContentService;
use Ibexa\Contracts\Core\Repository\ContentTypeService;
use Ibexa\Contracts\Core\Repository\FieldTypeService;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
#[AsCommand(
name: 'doc:view_content',
description: 'Output Field values on provided content item.'
)]
class ViewContentCommand extends Command
{
private ContentService $contentService;
private ContentTypeService $contentTypeService;
private FieldTypeService $fieldTypeService;
public function __construct(ContentService $contentService, ContentTypeService $contentTypeService, FieldTypeService $fieldTypeService)
{
$this->contentService = $contentService;
$this->contentTypeService = $contentTypeService;
$this->fieldTypeService = $fieldTypeService;
parent::__construct();
}
protected function configure(): void
{
$this
->setDefinition([
new InputArgument('contentId', InputArgument::REQUIRED, 'Location ID'),
]);
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$contentId = (int) $input->getArgument('contentId');
$content = $this->contentService->loadContent($contentId);
$contentType = $this->contentTypeService->loadContentType($content->contentInfo->contentTypeId);
foreach ($contentType->fieldDefinitions as $fieldDefinition) {
$output->writeln('Field: ' . $fieldDefinition->identifier);
$fieldType = $this->fieldTypeService->getFieldType($fieldDefinition->fieldTypeIdentifier);
$field = $content->getFieldValue($fieldDefinition->identifier);
$valueHash = $fieldType->toHash($field);
$output->writeln('Value:');
$output->writeln($valueHash);
}
return self::SUCCESS;
}
}