‪TYPO3CMS  9.5
ToggleExtensionInstallationStateViewHelper.php
Go to the documentation of this file.
1 <?php
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 
19 use TYPO3\CMS\Core\Package\PackageManager;
23 
29 {
33  protected ‪$tagName = 'a';
34 
36  protected ‪$objectManager;
37 
41  public function ‪injectObjectManager(\‪TYPO3\CMS\‪Extbase\Object\ObjectManagerInterface ‪$objectManager)
42  {
43  $this->objectManager = ‪$objectManager;
44  }
45 
49  public function ‪initializeArguments()
50  {
51  parent::initializeArguments();
52  $this->registerArgument('extension', 'array', '', true);
53  }
54 
60  public function ‪render()
61  {
62  $extension = $this->arguments['extension'];
63  // Early return if package is protected or is a runtime activated package and can not be unloaded
65  $packageManager = $this->objectManager->get(PackageManager::class);
66  $package = $packageManager->getPackage($extension['key']);
67  if ($package->isProtected() || in_array($extension['key'], ‪$GLOBALS['TYPO3_CONF_VARS']['EXT']['runtimeActivatedPackages'])) {
68  return '';
69  }
70 
71  $uriBuilder = $this->renderingContext->getControllerContext()->getUriBuilder();
72  $action = 'toggleExtensionInstallationState';
73  $uri = $uriBuilder->reset()->uriFor($action, [
74  'extensionKey' => $extension['key']
75  ], 'Action');
76  $this->tag->addAttribute('href', $uri);
77  $label = $extension['installed'] ? 'deactivate' : 'activate';
78  $this->tag->addAttribute('title', ‪LocalizationUtility::translate('extensionList.' . $label, 'extensionmanager'));
79  $icon = $extension['installed'] ? 'uninstall' : 'install';
80  $this->tag->addAttribute('class', 'onClickMaskExtensionManager btn btn-default');
81 
83  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
84  $this->tag->setContent($iconFactory->getIcon('actions-system-extension-' . $icon, ‪Icon::SIZE_SMALL)->render());
85  return $this->tag->render();
86  }
87 }
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:29
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:4
‪TYPO3\CMS\Extbase\Utility\LocalizationUtility
Definition: LocalizationUtility.php:29
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:25
‪TYPO3\CMS\Extensionmanager\ViewHelpers\ToggleExtensionInstallationStateViewHelper\$tagName
‪string $tagName
Definition: ToggleExtensionInstallationStateViewHelper.php:32
‪TYPO3
‪TYPO3\CMS\Extensionmanager\ViewHelpers\ToggleExtensionInstallationStateViewHelper\render
‪string render()
Definition: ToggleExtensionInstallationStateViewHelper.php:58
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:31
‪TYPO3\CMS\Extensionmanager\ViewHelpers
‪TYPO3\CMS\Extensionmanager\ViewHelpers\ToggleExtensionInstallationStateViewHelper\injectObjectManager
‪injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
Definition: ToggleExtensionInstallationStateViewHelper.php:39
‪TYPO3\CMS\Extbase\Utility\LocalizationUtility\translate
‪static string null translate($key, $extensionName=null, $arguments=null, string $languageKey=null, array $alternativeLanguageKeys=null)
Definition: LocalizationUtility.php:63
‪$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:34
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Extensionmanager\ViewHelpers\ToggleExtensionInstallationStateViewHelper\initializeArguments
‪initializeArguments()
Definition: ToggleExtensionInstallationStateViewHelper.php:47
‪TYPO3\CMS\Extensionmanager\ViewHelpers\ToggleExtensionInstallationStateViewHelper
Definition: ToggleExtensionInstallationStateViewHelper.php:29