4fedb54bee16e84dce163b1fc7161408bf4495bb
[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
23 /**
24 * Display a deactivate / activate link
25 * @internal
26 */
27 class ToggleExtensionInstallationStateViewHelper extends Link\ActionViewHelper
28 {
29 /**
30 * @var string
31 */
32 protected $tagName = 'a';
33
34 /**
35 * Initialize arguments
36 */
37 public function initializeArguments()
38 {
39 parent::initializeArguments();
40 $this->registerArgument('extension', 'array', '', true);
41 }
42
43 /**
44 * Renders an install link
45 *
46 * @return string the rendered a tag
47 */
48 public function render()
49 {
50 $extension = $this->arguments['extension'];
51 // Early return if package is protected or is a runtime activated package and can not be unloaded
52 /** @var $packageManager \TYPO3\CMS\Core\Package\PackageManager */
53 $packageManager = $this->objectManager->get(PackageManager::class);
54 $package = $packageManager->getPackage($extension['key']);
55 if ($package->isProtected() || in_array($extension['key'], $GLOBALS['TYPO3_CONF_VARS']['EXT']['runtimeActivatedPackages'])) {
56 return '';
57 }
58
59 $uriBuilder = $this->renderingContext->getControllerContext()->getUriBuilder();
60 $action = 'toggleExtensionInstallationState';
61 $uri = $uriBuilder->reset()->uriFor($action, [
62 'extensionKey' => $extension['key']
63 ], 'Action');
64 $this->tag->addAttribute('href', $uri);
65 $label = $extension['installed'] ? 'deactivate' : 'activate';
66 $this->tag->addAttribute('title', LocalizationUtility::translate('extensionList.' . $label, 'extensionmanager'));
67 $icon = $extension['installed'] ? 'uninstall' : 'install';
68 $this->tag->addAttribute('class', 'onClickMaskExtensionManager btn btn-default');
69
70 /** @var IconFactory $iconFactory */
71 $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
72 $this->tag->setContent($iconFactory->getIcon('actions-system-extension-' . $icon, Icon::SIZE_SMALL)->render());
73 return $this->tag->render();
74 }
75 }