phpStorm gives me the following comment:
Class 'UploadedFileReferenceConverter' is marked as @internal, the following code to handle an image upload should work for typo3 vs. , but I need a alternative for typo3 vs. 10
I read this, but I don't know how to use and where to place this code. Any help appreciated
New in version 10.2: Starting with version 10.2 a file can be retrieved directly by its filename from the folder::
$file = $folder->getFile(“filename.ext”);
/**
* action show
*
* @param \Covisiomedia\PdfGenerator\Domain\Model\Pdfgenerator $pdfgenerator
* @return string|object|null|void
*/
public function showAction(\Covisiomedia\PdfGenerator\Domain\Model\Pdfgenerator $pdfgenerator)
{
$this->view->assign('pdfgenerator', $pdfgenerator);
}
/**
* Set TypeConverter configuration for image upload
*
* @param string
*/
protected function setTypeConverterConfigurationForImageUpload($argumentName): void
{
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\Container\Container::class)
->registerImplementation(
\TYPO3\CMS\Extbase\Domain\Model\FileReference::class,
\Helhum\UploadExample\Domain\Model\FileReference::class
);
$uploadConfiguration = [
UploadedFileReferenceConverter::CONFIGURATION_UPLOAD_FOLDER =>
'1:/profilbild/',
];
/** @var PropertyMappingConfiguration $newExampleConfiguration */
$propertyMappingConfiguration = $this->arguments[$argumentName]->getPropertyMappingConfiguration();
$propertyMappingConfiguration->forProperty('image')
->setTypeConverterOptions(
UploadedFileReferenceConverter::class,
$uploadConfiguration
);
}
CodePudding user response:
Make your own UploadedFileReferenceConverter class with the content from https://github.com/helhum/upload_example/blob/master/Classes/Property/TypeConverter/UploadedFileReferenceConverter.php in Classes/Property/TypeConverter/ and use this
$propertyMappingConfiguration->forProperty('image')
->setTypeConverterOptions(
\Vendor\Extension\Property\TypeConverter\UploadedFileReferenceConverter::class,
$uploadConfiguration
);
CodePudding user response:
I tried the following and placed the UploadedFileReferenceConverter like recommended:
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
use TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration;
use Vendor\PdfGenerator\Property\TypeConverter\UploadedFileReferenceConverter;
...
protected function setTypeConverterConfigurationForImageUpload($argumentName)
{
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\Container\Container::class)
->registerImplementation(
\TYPO3\CMS\Extbase\Domain\Model\FileReference::class,
\Vendor\PdfGenerator\Domain\Model\FileReference::class
);
$uploadConfiguration = [
\Covisiomedia\PdfGenerator\Property\TypeConverter\UploadedFileReferenceConverter::CONFIGURATION_ALLOWED_FILE_EXTENSIONS => $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'],
UploadedFileReferenceConverter::CONFIGURATION_UPLOAD_FOLDER => '1:/user_upload/',
];
/** @var PropertyMappingConfiguration $newExampleConfiguration */
$newExampleConfiguration = $this->arguments[$argumentName]->getPropertyMappingConfiguration();
$newExampleConfiguration->forProperty('profilbild')
->setTypeConverterOptions(
UploadedFileReferenceConverter::class,
$uploadConfiguration
);
}
//the fluid form:
<f:form.upload property="profilbild">
<f:if condition="{resource}">
<f:image image="{resource}" alt="" width="50"/>
</f:if>
</f:form.upload>
I get the following error message. What went wrong?
Exception while property mapping at property path "profilbild": The identity property "AdobeStock_352234874.jpeg" is no UID.
