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