-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathViewCommand.php
More file actions
71 lines (57 loc) · 2.2 KB
/
Copy pathViewCommand.php
File metadata and controls
71 lines (57 loc) · 2.2 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
62
63
64
65
66
67
68
69
70
71
<?php declare(strict_types=1);
namespace App\Command;
use Ibexa\Core\MVC\Symfony\View\Builder\ContentViewBuilder;
use Ibexa\Core\MVC\Symfony\View\Renderer\TemplateRenderer;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
#[AsCommand(
name: 'app:view',
description: 'Render the view of a content item'
)]
class ViewCommand extends Command
{
private ContentViewBuilder $contentViewBuilder;
private TemplateRenderer $templateRenderer;
public function __construct(
ContentViewBuilder $contentViewBuilder,
TemplateRenderer $templateRenderer
) {
$this->contentViewBuilder = $contentViewBuilder;
$this->templateRenderer = $templateRenderer;
parent::__construct();
}
protected function configure(): void
{
$this
->addOption('content-id', 'c', InputOption::VALUE_OPTIONAL, 'Content ID')
->addOption('location-id', 'l', InputOption::VALUE_OPTIONAL, 'Location ID')
->addOption('view-type', 't', InputOption::VALUE_OPTIONAL, 'View Type', 'line');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$contentId = $input->getOption('content-id');
$locationId = $input->getOption('location-id');
if (empty($contentId) && empty($locationId)) {
throw new \InvalidArgumentException('No Content ID nor Location ID given');
}
$viewParameters = [
'viewType' => $input->getOption('view-type'),
'_controller' => 'ibexa_content:viewAction',
];
if (!empty($locationId)) {
$viewParameters['locationId'] = $locationId;
}
if (!empty($contentId)) {
$viewParameters['contentId'] = $contentId;
}
// build view
$contentView = $this->contentViewBuilder->buildView($viewParameters);
// render view
$renderedView = $this->templateRenderer->render($contentView);
$output->writeln($renderedView);
return 0;
}
}