0540881d279e8c39d5d7be7b51b0d7707dc24923
[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 /**
18 * Display a deactivate / activate link
19 * @internal
20 */
21 class ToggleExtensionInstallationStateViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Link\ActionViewHelper {
22
23 /**
24 * @var string
25 */
26 protected $tagName = 'a';
27
28 /**
29 * Renders an install link
30 *
31 * @param string $extension
32 * @return string the rendered a tag
33 */
34 public function render($extension) {
35 // Early return if package is protected or is a runtime actived package and can not be unloaded
36 /** @var $packageManager \TYPO3\CMS\Core\Package\PackageManager */
37 $packageManager = $this->objectManager->get(\TYPO3\CMS\Core\Package\PackageManager::class);
38 $package = $packageManager->getPackage($extension['key']);
39 if ($package->isProtected() || in_array($extension['key'], $GLOBALS['TYPO3_CONF_VARS']['EXT']['runtimeActivatedPackages'])) {
40 return '';
41 }
42
43 $uriBuilder = $this->controllerContext->getUriBuilder();
44 $action = 'toggleExtensionInstallationState';
45 $uri = $uriBuilder->reset()->uriFor($action, array(
46 'extensionKey' => $extension['key']
47 ), 'Action');
48 $this->tag->addAttribute('href', $uri);
49 $label = $extension['installed'] ? 'deactivate' : 'activate';
50 $this->tag->addAttribute('title', \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('extensionList.' . $label, 'extensionmanager'));
51 $icon = $extension['installed'] ? 'uninstall' : 'install';
52 $this->tag->addAttribute('class', 'onClickMaskExtensionManager btn btn-default');
53 $this->tag->setContent(\TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-system-extension-' . $icon));
54 return $this->tag->render();
55 }
56
57 }