‪TYPO3CMS  ‪main
UploadViewHelper.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 
36 {
40  protected ‪$tagName = 'input';
41 
42  public function ‪initializeArguments(): void
43  {
44  parent::initializeArguments();
45  $this->registerTagAttribute('disabled', 'string', 'Specifies that the input element should be disabled when the page loads');
46  $this->registerTagAttribute('multiple', 'string', 'Specifies that the file input element should allow multiple selection of files');
47  $this->registerTagAttribute('accept', 'string', 'Specifies the allowed file extensions to upload via comma-separated list, example ".png,.gif"');
48  $this->registerArgument('errorClass', 'string', 'CSS class to set if there are errors for this ViewHelper', false, 'f3-form-error');
49  $this->registerUniversalTagAttributes();
50  }
51 
52  public function ‪render(): string
53  {
54  $name = $this->‪getName();
55  $allowedFields = ['name', 'type', 'tmp_name', 'error', 'size'];
56  foreach ($allowedFields as $fieldName) {
57  $this->‪registerFieldNameForFormTokenGeneration($name . '[' . $fieldName . ']');
58  }
59  $this->tag->addAttribute('type', 'file');
60 
61  if (isset($this->arguments['multiple'])) {
62  $this->tag->addAttribute('name', $name . '[]');
63  } else {
64  $this->tag->addAttribute('name', $name);
65  }
66 
68  return $this->tag->render();
69  }
70 }
‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper\setErrorClassAttribute
‪setErrorClassAttribute()
Definition: AbstractFormFieldViewHelper.php:331
‪TYPO3\CMS\Fluid\ViewHelpers\Form\UploadViewHelper\render
‪render()
Definition: UploadViewHelper.php:51
‪TYPO3\CMS\Fluid\ViewHelpers\Form
Definition: AbstractFormFieldViewHelper.php:18
‪TYPO3\CMS\Fluid\ViewHelpers\Form\UploadViewHelper
Definition: UploadViewHelper.php:36
‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormViewHelper\registerFieldNameForFormTokenGeneration
‪registerFieldNameForFormTokenGeneration(string $fieldName)
Definition: AbstractFormViewHelper.php:100
‪TYPO3\CMS\Fluid\ViewHelpers\Form\UploadViewHelper\$tagName
‪string $tagName
Definition: UploadViewHelper.php:39
‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper\getName
‪getName()
Definition: AbstractFormFieldViewHelper.php:79
‪TYPO3\CMS\Fluid\ViewHelpers\Form\UploadViewHelper\initializeArguments
‪initializeArguments()
Definition: UploadViewHelper.php:41
‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper
Definition: AbstractFormFieldViewHelper.php:37