‪TYPO3CMS  ‪main
ToggleExtensionInstallationStateViewHelper.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
22 use TYPO3\CMS\Core\Imaging\IconSize;
24 use TYPO3\CMS\Core\Package\PackageManager;
29 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
30 
36 final class ‪ToggleExtensionInstallationStateViewHelper extends AbstractTagBasedViewHelper
37 {
41  protected ‪$tagName = 'a';
42 
43  public function ‪initializeArguments(): void
44  {
45  parent::initializeArguments();
46  $this->registerUniversalTagAttributes();
47  $this->registerArgument('extension', 'array', '', true);
48  }
49 
50  public function ‪render(): string
51  {
53  return '';
54  }
55 
56  $extension = $this->arguments['extension'];
57  $extension += [
58  'installed' => false,
59  ];
60  // Early return if package is protected and can not be unloaded
61  $packageManager = GeneralUtility::makeInstance(PackageManager::class);
62  $package = $packageManager->getPackage($extension['key']);
63  if ($package->isProtected()) {
64  return '';
65  }
66 
67  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
69  $renderingContext = $this->renderingContext;
71  $request = $renderingContext->getRequest();
72  $uriBuilder->setRequest($request);
73  $uri = $uriBuilder->reset()->uriFor(
74  'toggleExtensionInstallationState',
75  ['extensionKey' => $extension['key']],
76  'Action'
77  );
78  $this->tag->addAttribute('href', $uri);
79  $label = $extension['installed'] ? 'deactivate' : 'activate';
80  $this->tag->addAttribute('title', htmlspecialchars($this->‪getLanguageService()->sL(
81  'LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:extensionList.' . $label
82  )));
83  $icon = $extension['installed'] ? 'uninstall' : 'install';
84  $this->tag->addAttribute('class', 'onClickMaskExtensionManager btn btn-default');
85  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
86  $this->tag->setContent($iconFactory->getIcon('actions-system-extension-' . $icon, IconSize::SMALL)->render());
87  return $this->tag->render();
88  }
89 
90  protected function ‪getLanguageService(): ‪LanguageService
91  {
92  return ‪$GLOBALS['LANG'];
93  }
94 }
‪TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder
Definition: UriBuilder.php:38
‪TYPO3\CMS\Extensionmanager\ViewHelpers\ToggleExtensionInstallationStateViewHelper\$tagName
‪string $tagName
Definition: ToggleExtensionInstallationStateViewHelper.php:40
‪TYPO3\CMS\Core\Core\Environment\isComposerMode
‪static isComposerMode()
Definition: Environment.php:137
‪TYPO3\CMS\Extensionmanager\ViewHelpers\ToggleExtensionInstallationStateViewHelper\getLanguageService
‪getLanguageService()
Definition: ToggleExtensionInstallationStateViewHelper.php:89
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:34
‪TYPO3\CMS\Extensionmanager\ViewHelpers
‪TYPO3\CMS\Extensionmanager\ViewHelpers\ToggleExtensionInstallationStateViewHelper\render
‪render()
Definition: ToggleExtensionInstallationStateViewHelper.php:49
‪TYPO3\CMS\Extbase\Mvc\RequestInterface
Definition: RequestInterface.php:24
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:41
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext
Definition: RenderingContext.php:35
‪TYPO3\CMS\Extensionmanager\ViewHelpers\ToggleExtensionInstallationStateViewHelper\initializeArguments
‪initializeArguments()
Definition: ToggleExtensionInstallationStateViewHelper.php:42
‪TYPO3\CMS\Extensionmanager\ViewHelpers\ToggleExtensionInstallationStateViewHelper
Definition: ToggleExtensionInstallationStateViewHelper.php:37