‪TYPO3CMS  10.4
DownloadExtensionViewHelper.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 
25 
31 {
35  protected ‪$tagName = 'form';
36 
40  protected ‪$extensionService;
41 
46  {
47  $this->extensionService = ‪$extensionService;
48  }
49 
53  public function ‪initializeArguments()
54  {
55  parent::initializeArguments();
56  $this->registerArgument('extension', Extension::class, '', true);
57  $this->registerTagAttribute('enctype', 'string', 'MIME type with which the form is submitted');
58  $this->registerTagAttribute('method', 'string', 'Transfer type (GET or POST)');
59  $this->registerTagAttribute('name', 'string', 'Name of form');
60  $this->registerTagAttribute('onreset', 'string', 'JavaScript: On reset of the form');
61  $this->registerTagAttribute('onsubmit', 'string', 'JavaScript: On submit of the form');
62  $this->registerUniversalTagAttributes();
63  }
64 
70  public function ‪render()
71  {
73  $extension = $this->arguments['extension'];
75  if (empty($installPaths)) {
76  return '';
77  }
78  $pathSelector = '<ul class="extensionmanager-is-hidden">';
79  foreach ($installPaths as $installPathType => $installPath) {
81  $pathSelector .= '<li>
82  <input type="radio" id="' . htmlspecialchars($extension->getExtensionKey()) . '-downloadPath-' . htmlspecialchars($installPathType) . '" name="' . htmlspecialchars($this->‪getFieldNamePrefix()) . '[downloadPath]" class="downloadPath" value="' . htmlspecialchars($installPathType) . '" ' . ($installPathType === 'Local' ? 'checked="checked"' : '') . ' />
83  <label for="' . htmlspecialchars($extension->getExtensionKey()) . '-downloadPath-' . htmlspecialchars($installPathType) . '">' . htmlspecialchars($installPathType) . '</label>
84  </li>';
85  }
86  $pathSelector .= '</ul>';
88  $uriBuilder = $this->renderingContext->getControllerContext()->getUriBuilder();
89  $action = 'checkDependencies';
90  $uriBuilder->reset();
91  $uriBuilder->setFormat('json');
92  $uri = $uriBuilder->uriFor($action, [
93  'extension' => (int)$extension->getUid()
94  ], 'Download');
95  $this->tag->addAttribute('data-href', $uri);
96 
97  $automaticInstallation = (bool)GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('extensionmanager', 'automaticInstallation');
98  $labelKeySuffix = $automaticInstallation ? '' : '.downloadOnly';
99  $label = '
100  <div class="btn-group">
101  <button
102  title="' . ‪LocalizationUtility::translate('extensionList.downloadViewHelper.submit' . $labelKeySuffix, 'extensionmanager') . '"
103  type="submit"
104  class="btn btn-default"
105  value="' . ‪LocalizationUtility::translate('extensionList.downloadViewHelper.submit' . $labelKeySuffix, 'extensionmanager') . '"
106  >
107  <span class="t3-icon fa fa-cloud-download"></span>
108  </button>
109  </div>';
110 
111  $this->tag->setContent($label . $pathSelector);
112  $this->tag->addAttribute('class', 'download');
113  return '<div id="' . htmlspecialchars($extension->getExtensionKey()) . '-downloadFromTer" class="downloadFromTer">' . $this->tag->render() . '</div>';
114  }
115 
121  protected function ‪getFieldNamePrefix()
122  {
123  if ($this->hasArgument('fieldNamePrefix')) {
124  return $this->arguments['fieldNamePrefix'];
125  }
126  return $this->‪getDefaultFieldNamePrefix();
127  }
128 
134  protected function ‪getDefaultFieldNamePrefix()
135  {
136  $request = $this->renderingContext->getControllerContext()->getRequest();
137  if ($this->hasArgument('extensionName')) {
138  $extensionName = $this->arguments['extensionName'];
139  } else {
140  $extensionName = $request->getControllerExtensionName();
141  }
142  if ($this->hasArgument('pluginName')) {
143  $pluginName = $this->arguments['pluginName'];
144  } else {
145  $pluginName = $request->getPluginName();
146  }
147  if ($extensionName !== null && $pluginName != null) {
148  return $this->extensionService->getPluginNamespace($extensionName, $pluginName);
149  }
150  return '';
151  }
152 }
‪TYPO3\CMS\Extensionmanager\Domain\Model\Extension\returnAllowedInstallPaths
‪static array returnAllowedInstallPaths()
Definition: Extension.php:458
‪TYPO3\CMS\Extensionmanager\ViewHelpers\DownloadExtensionViewHelper\$extensionService
‪TYPO3 CMS Extbase Service ExtensionService $extensionService
Definition: DownloadExtensionViewHelper.php:38
‪TYPO3\CMS\Extbase\Utility\LocalizationUtility
Definition: LocalizationUtility.php:33
‪TYPO3\CMS\Extensionmanager\ViewHelpers\DownloadExtensionViewHelper\initializeArguments
‪initializeArguments()
Definition: DownloadExtensionViewHelper.php:51
‪TYPO3\CMS\Extensionmanager\Domain\Model\Extension
Definition: Extension.php:29
‪TYPO3\CMS\Extensionmanager\ViewHelpers\DownloadExtensionViewHelper\$tagName
‪string $tagName
Definition: DownloadExtensionViewHelper.php:34
‪TYPO3\CMS\Core\Configuration\ExtensionConfiguration
Definition: ExtensionConfiguration.php:45
‪TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder
Definition: UriBuilder.php:39
‪TYPO3\CMS\Extensionmanager\ViewHelpers
‪TYPO3\CMS\Extensionmanager\ViewHelpers\DownloadExtensionViewHelper\getDefaultFieldNamePrefix
‪string getDefaultFieldNamePrefix()
Definition: DownloadExtensionViewHelper.php:132
‪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
‪TYPO3\CMS\Extensionmanager\ViewHelpers\DownloadExtensionViewHelper\render
‪string render()
Definition: DownloadExtensionViewHelper.php:68
‪TYPO3\CMS\Extensionmanager\ViewHelpers\DownloadExtensionViewHelper\getFieldNamePrefix
‪string getFieldNamePrefix()
Definition: DownloadExtensionViewHelper.php:119
‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormViewHelper
Definition: AbstractFormViewHelper.php:31
‪TYPO3\CMS\Extbase\Service\ExtensionService
Definition: ExtensionService.php:33
‪TYPO3\CMS\Extensionmanager\ViewHelpers\DownloadExtensionViewHelper\injectExtensionService
‪injectExtensionService(ExtensionService $extensionService)
Definition: DownloadExtensionViewHelper.php:43
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Extensionmanager\ViewHelpers\DownloadExtensionViewHelper
Definition: DownloadExtensionViewHelper.php:31