‪TYPO3CMS  10.4
ToggleExtensionInstallationStateViewHelper.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
20 use TYPO3\CMS\Core\Package\PackageManager;
26 
32 {
36  protected ‪$tagName = 'a';
37 
39  protected ‪$objectManager;
40 
45  {
46  $this->objectManager = ‪$objectManager;
47  }
48 
52  public function ‪initializeArguments()
53  {
54  parent::initializeArguments();
55  $this->registerArgument('extension', 'array', '', true);
56  }
57 
63  public function ‪render()
64  {
65  $extension = $this->arguments['extension'];
66  // Early return if package is protected or is a runtime activated package and can not be unloaded
68  $packageManager = $this->objectManager->get(PackageManager::class);
69  $package = $packageManager->getPackage($extension['key']);
70  if ($package->isProtected() || in_array($extension['key'], ‪$GLOBALS['TYPO3_CONF_VARS']['EXT']['runtimeActivatedPackages'])) {
71  return '';
72  }
73 
75  $uriBuilder = $this->renderingContext->getControllerContext()->getUriBuilder();
76  $action = 'toggleExtensionInstallationState';
77  $uri = $uriBuilder->reset()->uriFor($action, [
78  'extensionKey' => $extension['key']
79  ], 'Action');
80  $this->tag->addAttribute('href', $uri);
81  $label = $extension['installed'] ? 'deactivate' : 'activate';
82  $this->tag->addAttribute('title', ‪LocalizationUtility::translate('extensionList.' . $label, 'extensionmanager'));
83  $icon = $extension['installed'] ? 'uninstall' : 'install';
84  $this->tag->addAttribute('class', 'onClickMaskExtensionManager btn btn-default');
85 
87  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
88  $this->tag->setContent($iconFactory->getIcon('actions-system-extension-' . $icon, ‪Icon::SIZE_SMALL)->render());
89  return $this->tag->render();
90  }
91 }
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:30
‪TYPO3\CMS\Extbase\Utility\LocalizationUtility
Definition: LocalizationUtility.php:33
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:26
‪TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder
Definition: UriBuilder.php:39
‪TYPO3\CMS\Extensionmanager\ViewHelpers\ToggleExtensionInstallationStateViewHelper\$tagName
‪string $tagName
Definition: ToggleExtensionInstallationStateViewHelper.php:35
‪TYPO3\CMS\Extensionmanager\ViewHelpers\ToggleExtensionInstallationStateViewHelper\render
‪string render()
Definition: ToggleExtensionInstallationStateViewHelper.php:61
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:33
‪TYPO3\CMS\Extbase\Object\ObjectManagerInterface
Definition: ObjectManagerInterface.php:26
‪TYPO3\CMS\Extensionmanager\ViewHelpers
‪TYPO3\CMS\Extensionmanager\ViewHelpers\ToggleExtensionInstallationStateViewHelper\injectObjectManager
‪injectObjectManager(ObjectManagerInterface $objectManager)
Definition: ToggleExtensionInstallationStateViewHelper.php:42
‪TYPO3\CMS\Extbase\Utility\LocalizationUtility\translate
‪static string null translate(string $key, ?string $extensionName=null, array $arguments=null, string $languageKey=null, array $alternativeLanguageKeys=null)
Definition: LocalizationUtility.php:67
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Extensionmanager\ViewHelpers\ToggleExtensionInstallationStateViewHelper\$objectManager
‪TYPO3 CMS Extbase Object ObjectManager $objectManager
Definition: ToggleExtensionInstallationStateViewHelper.php:37
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Extensionmanager\ViewHelpers\ToggleExtensionInstallationStateViewHelper\initializeArguments
‪initializeArguments()
Definition: ToggleExtensionInstallationStateViewHelper.php:50
‪TYPO3\CMS\Extensionmanager\ViewHelpers\ToggleExtensionInstallationStateViewHelper
Definition: ToggleExtensionInstallationStateViewHelper.php:32