after a long time of Google, I can get the categories of FAL Objects in Typo3 7.6 Fluid. But I can only return a String. I want to get an object like {data}.
What I
Looks like this task is very tricky. The file
object in the {files}
array is of type \TYPO3\CMS\Core\Resource\FileReference
where properties like uid, title or description are passed through from the original file object of type \TYPO3\CMS\Core\Resource\File
. FileReference
is actually implemented as a model but not file, so you can not extend it.
The only other way i see is to create a viewhelper that will get the categories with a native sql query and the CategoryRepository would automatically map the result to the Category model. Something like that:
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*/
class GetFileCategoriesViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
/**
* @var \TYPO3\CMS\Extbase\Domain\Repository\CategoryRepository
* @inject
*/
protected $categoryRepository;
/**
* @param int $uid
* @return array
*/
public function render ($uid) {
$query = $this->categoryRepository->createQuery();
$sql = "SELECT sys_category.* FROM sys_category
INNER JOIN sys_category_record_mm ON sys_category_record_mm.uid_local = sys_category.uid AND sys_category_record_mm.fieldname = 'categories' AND sys_category_record_mm.tablenames = 'sys_file_metadata'
INNER JOIN sys_file_metadata ON sys_category_record_mm.uid_foreign = sys_file_metadata.uid
WHERE sys_file_metadata.file = '" . (int)$uid . "'
AND sys_category.deleted = 0
ORDER BY sys_category_record_mm.sorting_foreign ASC";
return $query->statement($sql)->execute();
}
}
I have not tested the actual code, only the sql query, but this should work. Also i hope that you know how to include viewhelpers in your fluid template, if not I will provide an example.