Passed
Push — master ( bd92b3...0f6b9d )
by
unknown
18:59
created

DistributionController::injectPackageManager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the TYPO3 CMS project.
5
 *
6
 * It is free software; you can redistribute it and/or modify it under
7
 * the terms of the GNU General Public License, either version 2
8
 * of the License, or any later version.
9
 *
10
 * For the full copyright and license information, please read the
11
 * LICENSE.txt file that was distributed with this source code.
12
 *
13
 * The TYPO3 project - inspiring people to share!
14
 */
15
16
namespace TYPO3\CMS\Extensionmanager\Controller;
17
18
use Psr\Http\Message\ResponseInterface;
19
use TYPO3\CMS\Backend\Template\Components\ButtonBar;
20
use TYPO3\CMS\Backend\View\BackendTemplateView;
21
use TYPO3\CMS\Core\Imaging\Icon;
22
use TYPO3\CMS\Core\Package\PackageManager;
23
use TYPO3\CMS\Core\Page\PageRenderer;
24
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
25
use TYPO3\CMS\Extensionmanager\Domain\Model\Extension;
26
27
/**
28
 * Controller for distribution related actions
29
 * @internal This class is a specific controller implementation and is not considered part of the Public TYPO3 API.
30
 */
31
class DistributionController extends AbstractModuleController
32
{
33
    protected PackageManager $packageManager;
34
    protected PageRenderer $pageRenderer;
35
36
    public function __construct(PackageManager $packageManager, PageRenderer $pageRenderer)
37
    {
38
        $this->packageManager = $packageManager;
39
        $this->pageRenderer = $pageRenderer;
40
    }
41
42
    /**
43
     * Set up the doc header properly here
44
     *
45
     * @param ViewInterface $view
46
     */
47
    protected function initializeView(ViewInterface $view)
48
    {
49
        if ($view instanceof BackendTemplateView) {
50
            /** @var BackendTemplateView $view */
51
            parent::initializeView($view);
52
            $this->generateMenu();
53
            $this->registerDocHeaderButtons();
54
            $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Extensionmanager/DistributionImage');
55
        }
56
    }
57
58
    /**
59
     * Shows information about the distribution
60
     *
61
     * @param Extension $extension
62
     * @return ResponseInterface
63
     */
64
    public function showAction(Extension $extension): ResponseInterface
65
    {
66
        $extensionKey = $extension->getExtensionKey();
67
        // Check if extension/package is installed
68
        $active = $this->packageManager->isPackageActive($extensionKey);
69
70
        $this->view->assign('distributionActive', $active);
71
        $this->view->assign('extension', $extension);
72
73
        return $this->htmlResponse();
74
    }
75
76
    /**
77
     * Registers the Icons into the docheader
78
     *
79
     * @throws \InvalidArgumentException
80
     */
81
    protected function registerDocHeaderButtons()
82
    {
83
        /** @var ButtonBar $buttonBar */
84
        $buttonBar = $this->view->getModuleTemplate()->getDocHeaderComponent()->getButtonBar();
85
86
        $uri = $this->uriBuilder->reset()->uriFor('distributions', [], 'List');
87
        $title = $this->translate('extConfTemplate.backToList');
88
        $icon = $this->view->getModuleTemplate()->getIconFactory()->getIcon('actions-view-go-back', Icon::SIZE_SMALL);
89
        $button = $buttonBar->makeLinkButton()
90
            ->setHref($uri)
91
            ->setTitle($title)
92
            ->setIcon($icon);
93
        $buttonBar->addButton($button, ButtonBar::BUTTON_POSITION_LEFT);
94
    }
95
}
96