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