TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
DownloadExtensionViewHelper.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\ViewHelpers;
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 
25 {
29  protected $tagName = 'form';
30 
35 
39  protected $extensionService;
40 
44  public function injectExtensionService(\TYPO3\CMS\Extbase\Service\ExtensionService $extensionService)
45  {
46  $this->extensionService = $extensionService;
47  }
48 
52  public function injectConfigurationUtility(\TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility $configurationUtility)
53  {
54  $this->configurationUtility = $configurationUtility;
55  }
56 
60  public function initializeArguments()
61  {
62  parent::initializeArguments();
63  $this->registerArgument('extension', Extension::class, '', true);
64  $this->registerTagAttribute('enctype', 'string', 'MIME type with which the form is submitted');
65  $this->registerTagAttribute('method', 'string', 'Transfer type (GET or POST)');
66  $this->registerTagAttribute('name', 'string', 'Name of form');
67  $this->registerTagAttribute('onreset', 'string', 'JavaScript: On reset of the form');
68  $this->registerTagAttribute('onsubmit', 'string', 'JavaScript: On submit of the form');
70  }
71 
77  public function render()
78  {
80  $extension = $this->arguments['extension'];
81  $installPaths = Extension::returnAllowedInstallPaths();
82  if (empty($installPaths)) {
83  return '';
84  }
85  $pathSelector = '<ul class="is-hidden">';
86  foreach ($installPaths as $installPathType => $installPath) {
87  $pathSelector .= '<li>
88  <input type="radio" id="' . htmlspecialchars($extension->getExtensionKey()) . '-downloadPath-' . htmlspecialchars($installPathType) . '" name="' . htmlspecialchars($this->getFieldNamePrefix()) . '[downloadPath]" class="downloadPath" value="' . htmlspecialchars($installPathType) . '" ' . ($installPathType == 'Local' ? 'checked="checked"' : '') . ' />
89  <label for="' . htmlspecialchars($extension->getExtensionKey()) . '-downloadPath-' . htmlspecialchars($installPathType) . '">' . htmlspecialchars($installPathType) . '</label>
90  </li>';
91  }
92  $pathSelector .= '</ul>';
93  $uriBuilder = $this->controllerContext->getUriBuilder();
94  $action = 'checkDependencies';
95  $uriBuilder->reset();
96  $uriBuilder->setFormat('json');
97  $uri = $uriBuilder->uriFor($action, [
98  'extension' => (int)$extension->getUid()
99  ], 'Download');
100  $this->tag->addAttribute('data-href', $uri);
101 
102  $automaticInstallation = $this->configurationUtility->getCurrentConfiguration('extensionmanager')['automaticInstallation']['value'];
103  $labelKeySuffix = $automaticInstallation ? '' : '.downloadOnly';
104  $label = '
105  <div class="btn-group">
106  <button
107  title="' . LocalizationUtility::translate('extensionList.downloadViewHelper.submit' . $labelKeySuffix, 'extensionmanager') . '"
108  type="submit"
109  class="btn btn-default"
110  value="' . LocalizationUtility::translate('extensionList.downloadViewHelper.submit' . $labelKeySuffix, 'extensionmanager') . '"
111  >
112  <span class="t3-icon fa fa-cloud-download"></span>
113  </button>
114  </div>';
115 
116  $this->tag->setContent($label . $pathSelector);
117  $this->tag->addAttribute('class', 'download');
118  return '<div id="' . htmlspecialchars($extension->getExtensionKey()) . '-downloadFromTer" class="downloadFromTer">' . $this->tag->render() . '</div>';
119  }
120 
126  protected function getFieldNamePrefix()
127  {
128  if ($this->hasArgument('fieldNamePrefix')) {
129  return $this->arguments['fieldNamePrefix'];
130  } else {
131  return $this->getDefaultFieldNamePrefix();
132  }
133  }
134 
140  protected function getDefaultFieldNamePrefix()
141  {
142  $request = $this->controllerContext->getRequest();
143  if ($this->hasArgument('extensionName')) {
144  $extensionName = $this->arguments['extensionName'];
145  } else {
146  $extensionName = $request->getControllerExtensionName();
147  }
148  if ($this->hasArgument('pluginName')) {
149  $pluginName = $this->arguments['pluginName'];
150  } else {
151  $pluginName = $request->getPluginName();
152  }
153  if ($extensionName !== null && $pluginName != null) {
154  return $this->extensionService->getPluginNamespace($extensionName, $pluginName);
155  } else {
156  return '';
157  }
158  }
159 }
static translate($key, $extensionName, $arguments=null)
injectExtensionService(\TYPO3\CMS\Extbase\Service\ExtensionService $extensionService)
registerTagAttribute($name, $type, $description, $required=false, $default=null)
injectConfigurationUtility(\TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility $configurationUtility)