如何在Typo3内容元素图片的Fluid中获取类别对象? [英] How can I get the category object in Fluid of Typo3 Content Element Pictures?
问题描述
经过很长一段时间的Google,我可以在Typo3 7.6 Fluid中获得FAL对象的类别.但是我只能返回一个字符串.我想要一个类似{data}的对象.
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}.
我的工作: TypoScript
What I do: TypoScript
lib.category = CONTENT
lib.category {
table=sys_category
wrap=|
select {
pidInList = root,0,1
recursive = 99
max=10
selectFields=sys_category.title,sys_category.uid
join = sys_category_record_mm on sys_category_record_mm.uid_local = sys_category.uid join sys_file_metadata on sys_file_metadata.uid = sys_category_record_mm.uid_foreign join sys_file_reference on sys_file_reference.uid_local = sys_file_metadata.file
where.field = fuid
where.wrap = sys_file_reference.uid=|
}
renderObj=COA
renderObj {
1=TEXT
1.field = uid
2=TEXT
2.field = title
}
}
在Fluid中,我有:
In Fluid I have:
<f:for each="{files}" as="file">
<p>
- {file.uid}<br />
- <f:cObject typoscriptObjectPath="lib.category" data="{fuid:file.uid}" />
</p>
</f:for>
在网页上打印:
- 88
-
3Black7Small
- 88
3Black7Small
89
2Blue7Big
2Blue7Big
90
但是我认为Fluid中的一个对象更好,因此我可以对每个等使用f:.但是我不知道如何返回它.
But I think an object in Fluid is better, so I can use f:for each etc. But I don't know how I can return it.
有人可以帮助我吗?
推荐答案
看起来这个任务很棘手. {files}
数组中的file
对象的类型为\TYPO3\CMS\Core\Resource\FileReference
,其中uid,title或description等属性是从类型为\TYPO3\CMS\Core\Resource\File
的原始文件对象传递过来的. FileReference
实际上是作为模型而不是文件实现的,因此您不能扩展它.
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.
我看到的唯一另一种方法是创建一个viewhelper,它将使用本机sql查询获取类别,并且CategoryRepository会自动将结果映射到Category模型.像这样的东西:
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:
<?php
namespace Vendor\Extension\ViewHelpers;
/**
*
* @version $Id$
* @copyright Dimitri Lavrenuek <lavrenuek.de>
* @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();
}
}
我还没有测试实际的代码,只有sql查询,但这应该可以工作.我也希望您知道如何在流体模板中包含viewhelpers,否则,我将提供一个示例.
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.
这篇关于如何在Typo3内容元素图片的Fluid中获取类别对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!