TYPO3 CMS  TYPO3_8-7
PropertyMappingConfiguration.php
Go to the documentation of this file.
1 <?php
2 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 
26 
31 {
32 
50  public function afterBuildingFinished(RenderableInterface $renderable)
51  {
52  if ($renderable instanceof FileUpload) {
54  $propertyMappingConfiguration = $renderable->getRootForm()->getProcessingRule($renderable->getIdentifier())->getPropertyMappingConfiguration();
55 
56  $allowedMimeTypes = [];
57  $validators = [];
58 
59  if (is_array($renderable->getProperties()['allowedMimeTypes'])) {
60  $allowedMimeTypes = array_filter($renderable->getProperties()['allowedMimeTypes']);
61  }
62 
63  if (!empty($allowedMimeTypes)) {
64  $mimeTypeValidator = GeneralUtility::makeInstance(ObjectManager::class)
65  ->get(MimeTypeValidator::class, ['allowedMimeTypes' => $renderable->getProperties()['allowedMimeTypes']]);
66  $validators = [$mimeTypeValidator];
67  }
68 
69  $uploadConfiguration = [
72  ];
73 
74  $saveToFileMountIdentifier = (isset($renderable->getProperties()['saveToFileMount'])) ? $renderable->getProperties()['saveToFileMount'] : '';
75  if ($this->checkSaveFileMountAccess($saveToFileMountIdentifier)) {
76  $uploadConfiguration[UploadedFileReferenceConverter::CONFIGURATION_UPLOAD_FOLDER] = $saveToFileMountIdentifier;
77  } else {
78  $persistenceIdentifier = $renderable->getRootForm()->getPersistenceIdentifier();
79  if (!empty($persistenceIdentifier)) {
80  $pathinfo = PathUtility::pathinfo($persistenceIdentifier);
81  $saveToFileMountIdentifier = $pathinfo['dirname'];
82  if ($this->checkSaveFileMountAccess($saveToFileMountIdentifier)) {
83  $uploadConfiguration[UploadedFileReferenceConverter::CONFIGURATION_UPLOAD_FOLDER] = $saveToFileMountIdentifier;
84  }
85  }
86  }
87 
88  $propertyMappingConfiguration->setTypeConverterOptions(UploadedFileReferenceConverter::class, $uploadConfiguration);
89  }
90  }
91 
97  protected function checkSaveFileMountAccess(string $saveToFileMountIdentifier): bool
98  {
99  if (empty($saveToFileMountIdentifier)) {
100  return false;
101  }
102 
103  $resourceFactory = GeneralUtility::makeInstance(ObjectManager::class)
104  ->get(ResourceFactory::class);
105 
106  try {
107  $resourceFactory->getFolderObjectFromCombinedIdentifier($saveToFileMountIdentifier);
108  return true;
109  } catch (\InvalidArgumentException $e) {
110  return false;
111  }
112  }
113 }
static makeInstance($className,... $constructorArguments)
static pathinfo($path, $options=null)