[TASK] Remove unused ViewHelpers from extension manager
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / ViewHelpers / ToggleExtensionInstallationStateViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\ViewHelpers;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Imaging\Icon;
18 use TYPO3\CMS\Core\Imaging\IconFactory;
19 use TYPO3\CMS\Core\Package\PackageManager;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21 use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
22 use TYPO3\CMS\Fluid\ViewHelpers\Link\ActionViewHelper;
23
24 /**
25 * Display a deactivate / activate link
26 * @internal
27 */
28 class ToggleExtensionInstallationStateViewHelper extends ActionViewHelper
29 {
30 /**
31 * @var string
32 */
33 protected $tagName = 'a';
34
35 /** @var \TYPO3\CMS\Extbase\Object\ObjectManager */
36 protected $objectManager;
37
38 /**
39 * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
40 */
41 public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
42 {
43 $this->objectManager = $objectManager;
44 }
45
46 /**
47 * Initialize arguments
48 */
49 public function initializeArguments()
50 {
51 parent::initializeArguments();
52 $this->registerArgument('extension', 'array', '', true);
53 }
54
55 /**
56 * Renders an install link
57 *
58 * @return string the rendered a tag
59 */
60 public function render()
61 {
62 $extension = $this->arguments['extension'];
63 // Early return if package is protected or is a runtime activated package and can not be unloaded
64 /** @var $packageManager \TYPO3\CMS\Core\Package\PackageManager */
65 $packageManager = $this->objectManager->get(PackageManager::class);
66 $package = $packageManager->getPackage($extension['key']);
67 if ($package->isProtected() || in_array($extension['key'], $GLOBALS['TYPO3_CONF_VARS']['EXT']['runtimeActivatedPackages'])) {
68 return '';
69 }
70
71 $uriBuilder = $this->renderingContext->getControllerContext()->getUriBuilder();
72 $action = 'toggleExtensionInstallationState';
73 $uri = $uriBuilder->reset()->uriFor($action, [
74 'extensionKey' => $extension['key']
75 ], 'Action');
76 $this->tag->addAttribute('href', $uri);
77 $label = $extension['installed'] ? 'deactivate' : 'activate';
78 $this->tag->addAttribute('title', LocalizationUtility::translate('extensionList.' . $label, 'extensionmanager'));
79 $icon = $extension['installed'] ? 'uninstall' : 'install';
80 $this->tag->addAttribute('class', 'onClickMaskExtensionManager btn btn-default');
81
82 /** @var IconFactory $iconFactory */
83 $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
84 $this->tag->setContent($iconFactory->getIcon('actions-system-extension-' . $icon, Icon::SIZE_SMALL)->render());
85 return $this->tag->render();
86 }
87 }