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