TYPO3: get and display all file categories in fluid

224 Views Asked by At

TYPO3 11.5.33

Task I want to display every category title of a pdf file in a comma separated list in a table column.

I have the content element of CType = uploads and inside I have a sys_file_collection for a folder with pdf files. I iterate over the {files} array to create a table with columns for example a preview icon, file title, file size and the categories, which were assigned to the file.

<f:for each="{files}" as="file" iteration="fileIterator">
<!-- table code -->
</f:for>

For example:

   Image    |   Title   |  Category  | Filesize
preview pic   PDF Title   cat1, cat2     3 MB
preview pic   PDF Title2  cat3           5 MB

Everything is working except the output of the categories.

If I debug the {file} array I get the following information:

Debug information

and inside metaDataAspect there are a lot of properties.

There is categories but this has only an integer value, for the number of categories which are selected for that file.

categories

In the Slack channel I was told a dataProcessor is best suited for this use case and was recommended this https://docs.typo3.org/m/typo3/reference-typoscript/11.5/en-us/ContentObjects/Fluidtemplate/DataProcessing/DatabaseQueryProcessor.html

After spending some time on it I have no idea how to get this working.

I also found this WIP task https://forge.typo3.org/issues/82010 | https://review.typo3.org/c/Packages/TYPO3.CMS/+/62123 but it's still not finished and I'm also not sure if that would work with files.

Is there really no out-of-the-box solution for this problem?

Had someone a similar problem already and can help with a solution or is there an existing vhs viewhelper for this purpose?

1

There are 1 best solutions below

6
Bernd Wilke πφ On

The output of the uploads CE (content Element) is configured in your typoscript at tt_content.uploads. There you can find the FilesProcessor which provides your list of file data for the FLUID.

As you noticed the category field is just added as is without resolving the relation.

You can/ must add another processor (a databaseQueryProcessor) for resolving these relation:

tt_content {
  uploads {
    dataProcessing {
      10 {
        dataProcessing [
          10 = TYPO3\CMS\Frontend\DataProcessing\DatabaseQueryProcessor
          10 {
            if.isTrue.field = categories
            table = sys_category
            pidInList = root,-1
            selectFields = sys_category.*
            join = sys_category_record_mm ON sys_category_record_mm.uid_local = sys_category.uid
            where.data = field:_ORIG_uid // field:uid
            where.intval = 1
            where.wrap = sys_category_record_mm.uid_foreign=|
            orderBy = sys_category_record_mm.sorting_foreign
            languageField = 0 # disable translation handling of sys_category
            as = categoryList
          }
        }
      }
    }
  }
}

In the manual you can find an example for a customCategoryProcessor which handles exactly your problem. The needed PHP is given in the 'TYPO3 explained'-manual