| Conditions | 11 |
| Paths | 50 |
| Total Lines | 73 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 50 | public function afterBuildingFinished(RenderableInterface $renderable) |
||
| 51 | { |
||
| 52 | if ($renderable instanceof FileUpload) { |
||
| 53 | // Set the property mapping configuration for the file upload element. |
||
| 54 | // * Add the UploadedFileReferenceConverter to convert an uploaded file to a |
||
| 55 | // FileReference. |
||
| 56 | // * Add the MimeTypeValidator to the UploadedFileReferenceConverter to |
||
| 57 | // delete non-valid file types directly. |
||
| 58 | // * Setup the storage: |
||
| 59 | // If the property "saveToFileMount" exist for this element it will be used. |
||
| 60 | // If this file mount or the property "saveToFileMount" does not exist |
||
| 61 | // the default storage "1:/user_uploads/" will be used. Uploads are placed |
||
| 62 | // in a dedicated sub-folder (e.g. ".../form_<40-chars-hash>/actual.file"). |
||
| 63 | |||
| 64 | /** @var UploadedFileReferenceConverter $typeConverter */ |
||
| 65 | $typeConverter = GeneralUtility::makeInstance(ObjectManager::class) |
||
| 66 | ->get(UploadedFileReferenceConverter::class); |
||
| 67 | /** @var \TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration $propertyMappingConfiguration */ |
||
| 68 | $propertyMappingConfiguration = $renderable->getRootForm() |
||
| 69 | ->getProcessingRule($renderable->getIdentifier()) |
||
| 70 | ->getPropertyMappingConfiguration() |
||
| 71 | ->setTypeConverter($typeConverter); |
||
| 72 | |||
| 73 | $allowedMimeTypes = []; |
||
| 74 | $validators = []; |
||
| 75 | if (isset($renderable->getProperties()['allowedMimeTypes']) && \is_array($renderable->getProperties()['allowedMimeTypes'])) { |
||
| 76 | $allowedMimeTypes = array_filter($renderable->getProperties()['allowedMimeTypes']); |
||
| 77 | } |
||
| 78 | if (!empty($allowedMimeTypes)) { |
||
| 79 | $mimeTypeValidator = GeneralUtility::makeInstance(ObjectManager::class) |
||
| 80 | ->get(MimeTypeValidator::class, ['allowedMimeTypes' => $allowedMimeTypes]); |
||
| 81 | $validators = [$mimeTypeValidator]; |
||
| 82 | } |
||
| 83 | |||
| 84 | $processingRule = $renderable->getRootForm()->getProcessingRule($renderable->getIdentifier()); |
||
| 85 | foreach ($processingRule->getValidators() as $validator) { |
||
| 86 | if (!($validator instanceof NotEmptyValidator)) { |
||
| 87 | $validators[] = $validator; |
||
| 88 | $processingRule->removeValidator($validator); |
||
| 89 | } |
||
| 90 | } |
||
| 91 | |||
| 92 | $uploadConfiguration = [ |
||
| 93 | UploadedFileReferenceConverter::CONFIGURATION_FILE_VALIDATORS => $validators, |
||
| 94 | UploadedFileReferenceConverter::CONFIGURATION_UPLOAD_CONFLICT_MODE => 'rename', |
||
| 95 | ]; |
||
| 96 | |||
| 97 | $saveToFileMountIdentifier = $renderable->getProperties()['saveToFileMount'] ?? ''; |
||
| 98 | if ($this->checkSaveFileMountAccess($saveToFileMountIdentifier)) { |
||
| 99 | $uploadConfiguration[UploadedFileReferenceConverter::CONFIGURATION_UPLOAD_FOLDER] = $saveToFileMountIdentifier; |
||
| 100 | } else { |
||
| 101 | // @todo Why should uploaded files be stored to the same directory as the *.form.yaml definitions? |
||
| 102 | $persistenceIdentifier = $renderable->getRootForm()->getPersistenceIdentifier(); |
||
| 103 | if (!empty($persistenceIdentifier)) { |
||
| 104 | $pathinfo = PathUtility::pathinfo($persistenceIdentifier); |
||
| 105 | $saveToFileMountIdentifier = $pathinfo['dirname']; |
||
| 106 | if ($this->checkSaveFileMountAccess($saveToFileMountIdentifier)) { |
||
| 107 | $uploadConfiguration[UploadedFileReferenceConverter::CONFIGURATION_UPLOAD_FOLDER] = $saveToFileMountIdentifier; |
||
| 108 | } |
||
| 109 | } |
||
| 110 | } |
||
| 111 | $propertyMappingConfiguration->setTypeConverterOptions(UploadedFileReferenceConverter::class, $uploadConfiguration); |
||
| 112 | return; |
||
| 113 | } |
||
| 114 | |||
| 115 | if ($renderable->getType() === 'Date') { |
||
| 116 | // Set the property mapping configuration for the `Date` element. |
||
| 117 | |||
| 118 | /** @var \TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration $propertyMappingConfiguration */ |
||
| 119 | $propertyMappingConfiguration = $renderable->getRootForm()->getProcessingRule($renderable->getIdentifier())->getPropertyMappingConfiguration(); |
||
|
|
|||
| 120 | // @see https://www.w3.org/TR/2011/WD-html-markup-20110405/input.date.html#input.date.attrs.value |
||
| 121 | // 'Y-m-d' = https://tools.ietf.org/html/rfc3339#section-5.6 -> full-date |
||
| 122 | $propertyMappingConfiguration->setTypeConverterOption(DateTimeConverter::class, DateTimeConverter::CONFIGURATION_DATE_FORMAT, 'Y-m-d'); |
||
| 123 | } |
||
| 194 |