‪TYPO3CMS  9.5
DownloadExtensionViewHelper.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 
21 
27 {
31  protected ‪$tagName = 'form';
32 
36  protected ‪$extensionService;
37 
41  public function ‪injectExtensionService(\‪TYPO3\CMS\‪Extbase\Service\ExtensionService ‪$extensionService)
42  {
43  $this->extensionService = ‪$extensionService;
44  }
45 
49  public function ‪initializeArguments()
50  {
51  parent::initializeArguments();
52  $this->registerArgument('extension', Extension::class, '', true);
53  $this->registerTagAttribute('enctype', 'string', 'MIME type with which the form is submitted');
54  $this->registerTagAttribute('method', 'string', 'Transfer type (GET or POST)');
55  $this->registerTagAttribute('name', 'string', 'Name of form');
56  $this->registerTagAttribute('onreset', 'string', 'JavaScript: On reset of the form');
57  $this->registerTagAttribute('onsubmit', 'string', 'JavaScript: On submit of the form');
58  $this->registerUniversalTagAttributes();
59  }
60 
66  public function ‪render()
67  {
69  $extension = $this->arguments['extension'];
71  if (empty($installPaths)) {
72  return '';
73  }
74  $pathSelector = '<ul class="is-hidden">';
75  foreach ($installPaths as $installPathType => $installPath) {
76  $pathSelector .= '<li>
77  <input type="radio" id="' . htmlspecialchars($extension->getExtensionKey()) . '-downloadPath-' . htmlspecialchars($installPathType) . '" name="' . htmlspecialchars($this->‪getFieldNamePrefix()) . '[downloadPath]" class="downloadPath" value="' . htmlspecialchars($installPathType) . '" ' . ($installPathType === 'Local' ? 'checked="checked"' : '') . ' />
78  <label for="' . htmlspecialchars($extension->getExtensionKey()) . '-downloadPath-' . htmlspecialchars($installPathType) . '">' . htmlspecialchars($installPathType) . '</label>
79  </li>';
80  }
81  $pathSelector .= '</ul>';
82  $uriBuilder = $this->renderingContext->getControllerContext()->getUriBuilder();
83  $action = 'checkDependencies';
84  $uriBuilder->reset();
85  $uriBuilder->setFormat('json');
86  $uri = $uriBuilder->uriFor($action, [
87  'extension' => (int)$extension->getUid()
88  ], 'Download');
89  $this->tag->addAttribute('data-href', $uri);
90 
91  $automaticInstallation = (bool)GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('extensionmanager', 'automaticInstallation');
92  $labelKeySuffix = $automaticInstallation ? '' : '.downloadOnly';
93  $label = '
94  <div class="btn-group">
95  <button
96  title="' . ‪LocalizationUtility::translate('extensionList.downloadViewHelper.submit' . $labelKeySuffix, 'extensionmanager') . '"
97  type="submit"
98  class="btn btn-default"
99  value="' . ‪LocalizationUtility::translate('extensionList.downloadViewHelper.submit' . $labelKeySuffix, 'extensionmanager') . '"
100  >
101  <span class="t3-icon fa fa-cloud-download"></span>
102  </button>
103  </div>';
104 
105  $this->tag->setContent($label . $pathSelector);
106  $this->tag->addAttribute('class', 'download');
107  return '<div id="' . htmlspecialchars($extension->getExtensionKey()) . '-downloadFromTer" class="downloadFromTer">' . $this->tag->render() . '</div>';
108  }
109 
115  protected function ‪getFieldNamePrefix()
116  {
117  if ($this->hasArgument('fieldNamePrefix')) {
118  return $this->arguments['fieldNamePrefix'];
119  }
120  return $this->‪getDefaultFieldNamePrefix();
121  }
122 
128  protected function ‪getDefaultFieldNamePrefix()
129  {
130  $request = $this->renderingContext->getControllerContext()->getRequest();
131  if ($this->hasArgument('extensionName')) {
132  $extensionName = $this->arguments['extensionName'];
133  } else {
134  $extensionName = $request->getControllerExtensionName();
135  }
136  if ($this->hasArgument('pluginName')) {
137  $pluginName = $this->arguments['pluginName'];
138  } else {
139  $pluginName = $request->getPluginName();
140  }
141  if ($extensionName !== null && $pluginName != null) {
142  return $this->extensionService->getPluginNamespace($extensionName, $pluginName);
143  }
144  return '';
145  }
146 }
‪TYPO3\CMS\Extensionmanager\Domain\Model\Extension\returnAllowedInstallPaths
‪static array returnAllowedInstallPaths()
Definition: Extension.php:449
‪TYPO3\CMS\Extensionmanager\ViewHelpers\DownloadExtensionViewHelper\$extensionService
‪TYPO3 CMS Extbase Service ExtensionService $extensionService
Definition: DownloadExtensionViewHelper.php:34
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:4
‪TYPO3\CMS\Extbase\Utility\LocalizationUtility
Definition: LocalizationUtility.php:29
‪TYPO3\CMS\Extensionmanager\ViewHelpers\DownloadExtensionViewHelper\initializeArguments
‪initializeArguments()
Definition: DownloadExtensionViewHelper.php:47
‪TYPO3\CMS\Extensionmanager\Domain\Model\Extension
Definition: Extension.php:24
‪TYPO3\CMS\Extensionmanager\ViewHelpers\DownloadExtensionViewHelper\$tagName
‪string $tagName
Definition: DownloadExtensionViewHelper.php:30
‪TYPO3\CMS\Core\Configuration\ExtensionConfiguration
Definition: ExtensionConfiguration.php:42
‪TYPO3
‪TYPO3\CMS\Extensionmanager\ViewHelpers
‪TYPO3\CMS\Extensionmanager\ViewHelpers\DownloadExtensionViewHelper\getDefaultFieldNamePrefix
‪string getDefaultFieldNamePrefix()
Definition: DownloadExtensionViewHelper.php:126
‪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
‪TYPO3\CMS\Extensionmanager\ViewHelpers\DownloadExtensionViewHelper\injectExtensionService
‪injectExtensionService(\TYPO3\CMS\Extbase\Service\ExtensionService $extensionService)
Definition: DownloadExtensionViewHelper.php:39
‪TYPO3\CMS\Extensionmanager\ViewHelpers\DownloadExtensionViewHelper\render
‪string render()
Definition: DownloadExtensionViewHelper.php:64
‪TYPO3\CMS\Extensionmanager\ViewHelpers\DownloadExtensionViewHelper\getFieldNamePrefix
‪string getFieldNamePrefix()
Definition: DownloadExtensionViewHelper.php:113
‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormViewHelper
Definition: AbstractFormViewHelper.php:26
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Extensionmanager\ViewHelpers\DownloadExtensionViewHelper
Definition: DownloadExtensionViewHelper.php:27