‪TYPO3CMS  ‪main
DownloadExtensionViewHelper.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;
31 
38 {
42  protected ‪$tagName = 'form';
43 
46 
48  {
49  $this->extensionService = ‪$extensionService;
50  }
51 
53  {
54  $this->iconFactory = ‪$iconFactory;
55  }
56 
57  public function ‪initializeArguments(): void
58  {
59  parent::initializeArguments();
60  $this->registerArgument('extension', Extension::class, '', true);
61  $this->registerUniversalTagAttributes();
62  }
63 
64  public function ‪render(): string
65  {
67  $extension = $this->arguments['extension'];
68  $installPaths = ‪Extension::returnInstallPaths();
69  $pathSelector = '<ul class="extensionmanager-is-hidden">';
70  foreach ($installPaths as $installPathType => $installPath) {
72  $pathSelector .= '<li>
73  <input type="radio" id="' . htmlspecialchars($extension->getExtensionKey()) . '-downloadPath-' . htmlspecialchars($installPathType) . '" name="downloadPath" class="downloadPath" value="' . htmlspecialchars($installPathType) . '" ' . ($installPathType === 'Local' ? 'checked="checked"' : '') . ' />
74  <label for="' . htmlspecialchars($extension->getExtensionKey()) . '-downloadPath-' . htmlspecialchars($installPathType) . '">' . htmlspecialchars($installPathType) . '</label>
75  </li>';
76  }
77  $pathSelector .= '</ul>';
78  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
80  $renderingContext = $this->renderingContext;
82  $request = $renderingContext->getRequest();
83  $uriBuilder->setRequest($request);
84  $action = 'checkDependencies';
85  $uriBuilder->reset();
86  $uriBuilder->setFormat('json');
87  $uri = $uriBuilder->uriFor($action, [
88  'extension' => (int)$extension->getUid(),
89  ], 'Download');
90  $this->tag->addAttribute('data-href', $uri);
91 
92  $automaticInstallation = (bool)GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('extensionmanager', 'automaticInstallation');
93  $labelKeySuffix = $automaticInstallation ? '' : '.downloadOnly';
94  $titleAndValue = $this->‪getLanguageService()->sL(
95  'LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:extensionList.downloadViewHelper.submit' . $labelKeySuffix
96  );
97  $label = '
98  <div class="btn-group">
99  <button
100  title="' . htmlspecialchars($titleAndValue) . '"
101  type="submit"
102  class="btn btn-default"
103  value="' . htmlspecialchars($titleAndValue) . '"
104  >
105  ' . $this->iconFactory->getIcon('actions-download', IconSize::SMALL)->render() . '
106  </button>
107  </div>';
108 
109  $this->tag->setContent($label . $pathSelector);
110  $this->tag->addAttribute('class', $this->arguments['class']);
111  return '<div id="' . htmlspecialchars($extension->getExtensionKey()) . '-downloadFromTer" class="downloadFromTer">' . $this->tag->render() . '</div>';
112  }
113 
114  protected function ‪getLanguageService(): ‪LanguageService
115  {
116  return ‪$GLOBALS['LANG'];
117  }
118 }
‪TYPO3\CMS\Extensionmanager\ViewHelpers\DownloadExtensionViewHelper\getLanguageService
‪getLanguageService()
Definition: DownloadExtensionViewHelper.php:113
‪TYPO3\CMS\Extensionmanager\ViewHelpers\DownloadExtensionViewHelper\initializeArguments
‪initializeArguments()
Definition: DownloadExtensionViewHelper.php:56
‪TYPO3\CMS\Extensionmanager\Domain\Model\Extension
Definition: Extension.php:30
‪TYPO3\CMS\Extensionmanager\ViewHelpers\DownloadExtensionViewHelper\$tagName
‪string $tagName
Definition: DownloadExtensionViewHelper.php:41
‪TYPO3\CMS\Core\Configuration\ExtensionConfiguration
Definition: ExtensionConfiguration.php:47
‪TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder
Definition: UriBuilder.php:38
‪TYPO3\CMS\Extensionmanager\ViewHelpers\DownloadExtensionViewHelper\render
‪render()
Definition: DownloadExtensionViewHelper.php:63
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:34
‪TYPO3\CMS\Extensionmanager\ViewHelpers\DownloadExtensionViewHelper\injectIconFactory
‪injectIconFactory(IconFactory $iconFactory)
Definition: DownloadExtensionViewHelper.php:51
‪TYPO3\CMS\Extensionmanager\ViewHelpers\DownloadExtensionViewHelper\$iconFactory
‪IconFactory $iconFactory
Definition: DownloadExtensionViewHelper.php:44
‪TYPO3\CMS\Extensionmanager\ViewHelpers
‪TYPO3\CMS\Extensionmanager\Domain\Model\Extension\returnInstallPaths
‪static returnInstallPaths()
Definition: Extension.php:297
‪TYPO3\CMS\Extbase\Mvc\RequestInterface
Definition: RequestInterface.php:24
‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormViewHelper
Definition: AbstractFormViewHelper.php:35
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Extensionmanager\ViewHelpers\DownloadExtensionViewHelper\$extensionService
‪ExtensionService $extensionService
Definition: DownloadExtensionViewHelper.php:43
‪TYPO3\CMS\Extbase\Service\ExtensionService
Definition: ExtensionService.php:34
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Extensionmanager\ViewHelpers\DownloadExtensionViewHelper\injectExtensionService
‪injectExtensionService(ExtensionService $extensionService)
Definition: DownloadExtensionViewHelper.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\DownloadExtensionViewHelper
Definition: DownloadExtensionViewHelper.php:38