How to upload PDF files from femanager extension TYPO3 11.5

132 Views Asked by At

I am tryng to upload pdf files from the frontend with the user profile form (femanager), it only allows me to use the "Image" field, but for this case more pdf file fields are needed.

I have the following custom field for it

<f:form.upload
id="femanager_field_pdf"
property="pdf.0"
class="custom-file-input" />

In the extended User class

/**
* @var ObjectStorage<FileReference>
*/
protected $pdf;

/**
* Gets the pdf value
*
* @return ObjectStorage<FileReference>
*/
public function getPdf()
{
return $this->pdf;
}
/**
* Sets the pdf value
*
* @param ObjectStorage<FileReference> $pdf
*/
public function setpdf(ObjectStorage $pdf)
{
$this->pdf = $pdf;
}

I expected that when saving the user profile form the file would be saved in the "pdf" field but it generates an error

Exception while property mapping at property path "pdf.0": Property "name" was not found in target object of type "TYPO3\CMS\Extbase\Domain\Model\FileReference".
1

There are 1 best solutions below

0
Laars On

For fe_manager you need to add a new DataProcessor.

See TypoScript setup:

plugin.tx_femanager.settings.dataProcessors.100 {
    #Classname that should be called with an existing method process()
    class = Vendor\Ext\DataProcessor\DoSomethingDataProcessor

    #optional: Add configuration for your PHP
    config {
        foo = bar

        fooCObject = TEXT
        fooCObject.value = do something with this text
    }

    #call this class just before this actions will be opened
    events {
        New = create,createStatus
    }
}

Then add a new DataProcessor class. See In2code\Femanager\DataProcessor for example.

Background: The image or PDF needs to be uploaded to the server first. Then a sys_file_reference needs to be created. After that the request arguments are change to the new file UID.