fda413b39ef9ea30090c8da2a16377a45473c44a
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / ViewHelpers / RemoveExtensionViewHelper.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 * view helper for displaying a remove extension link
23 * @internal
24 */
25 class RemoveExtensionViewHelper extends Link\ActionViewHelper
26 {
27 /**
28 * Initialize arguments
29 *
30 * @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception
31 */
32 public function initializeArguments()
33 {
34 parent::initializeArguments();
35 $this->registerArgument('extension', 'array', '', true);
36 }
37
38 /**
39 * Renders an install link
40 *
41 * @return string the rendered a tag
42 */
43 public function render()
44 {
45 $extension = $this->arguments['extension'];
46 $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
47 if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded($extension['key'])) {
48 return '<span class="btn btn-default disabled">' . $iconFactory->getIcon('empty-empty', Icon::SIZE_SMALL)->render() . '</span>';
49 }
50 if (
51 !in_array($extension['type'], \TYPO3\CMS\Extensionmanager\Domain\Model\Extension::returnAllowedInstallTypes()) ||
52 $extension['type'] === 'System'
53 ) {
54 return '<span class="btn btn-default disabled">' . $iconFactory->getIcon('empty-empty', Icon::SIZE_SMALL)->render() . '</span>';
55 }
56 $uriBuilder = $this->renderingContext->getControllerContext()->getUriBuilder();
57 $action = 'removeExtension';
58 $uriBuilder->reset();
59 $uriBuilder->setFormat('json');
60 $uri = $uriBuilder->uriFor($action, [
61 'extension' => $extension['key']
62 ], 'Action');
63 $this->tag->addAttribute('href', $uri);
64 $cssClass = 'removeExtension btn btn-default';
65 $this->tag->addAttribute('class', $cssClass);
66 $this->tag->addAttribute('title', \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('extensionList.remove', 'extensionmanager'));
67 $this->tag->setContent($iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL)->render());
68 return $this->tag->render();
69 }
70 }