使用数据处理器将TYPO3内容元素呈现为Humenu
几个小时以来,我一直在尝试创建一个内容元素菜单,点击链接可以跳转到CE的锚点。我找到了一个解决方案,它是用打字稿制作的,但是现代的方式应该使用数据处理。到目前为止,我以多种组合和级联方式尝试了所有默认处理器,然后扩展了原始MenuProcessor,并在其中合并了DatabaseQueryProcessor中的一些函数,以查询tt_内容表 什么都没有成功!将这个小代码示例的功能编写为DataProcessor不可能是如此复杂的任务?!非常令人沮丧-你们有人有想法吗使用数据处理器将TYPO3内容元素呈现为Humenu,typo3,Typo3,几个小时以来,我一直在尝试创建一个内容元素菜单,点击链接可以跳转到CE的锚点。我找到了一个解决方案,它是用打字稿制作的,但是现代的方式应该使用数据处理。到目前为止,我以多种组合和级联方式尝试了所有默认处理器,然后扩展了原始MenuProcessor,并在其中合并了DatabaseQueryProcessor中的一些函数,以查询tt_内容表 什么都没有成功!将这个小代码示例的功能编写为DataProcessor不可能是如此复杂的任务?!非常令人沮丧-你们有人有想法吗 temp.contentnav
temp.contentnav = CONTENT
temp.contentnav.wrap = <ul>|</ul>
temp.contentnav {
table = tt_content
select {
pidInList = this
andWhere = (sectionIndex=1 AND hidden=0 AND deleted=0)
orderBy = sorting DESC
where = colPos=0
languageField=sys_language_uid
}
renderObj = TEXT
renderObj {
field = header
wrap= <li>|</li>
typolink.parameter.field=pid
typolink.parameter.dataWrap=|#{field:uid}
if.isTrue.field=header
}
}
lib.sub_nav < temp.contentnav
temp.contentnav=CONTENT
temp.contentnav.wrap=|
临时内容导航{
表=tt_含量
挑选{
pidInList=这个
andWhere=(sectionIndex=1,hidden=0,deleted=0)
orderBy=排序描述
其中=colPos=0
languageField=sys\u language\u uid
}
renderObj=文本
伦德罗布{
字段=标题
包裹=|
typlink.parameter.field=pid
typlink.parameter.dataWrap=|#{field:uid}
if.isTrue.field=标题
}
}
lib.sub_导航
来源:在玩了更多的游戏之后,我找到了一个可行的解决方案,使用
userFunc
覆盖MenuProcessor
的返回结果。但我的直觉告诉我,这不是一个很好的解决方案,更像是一个权宜之计,我认为一定有比这更好的办法。请随时改进或发表您的意见:
page.10 {
dataProcessing {
110 = TYPO3\CMS\Frontend\DataProcessing\MenuProcessor
110 {
special = userfunction
special {
userFunc = Vendor\Extension\ContentMenu->process
table = tt_content
pidInList = 9 # Page where the content comes from, uid possible
titleField = header
}
as = contentmenu
}
}
}
以及:
class ContentMenu {
/**
* @var \TYPO3\CMS\Frontend\ContentObject\ContentDataProcessor
*/
protected $contentDataProcessor;
/**
* @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
*/
public $cObj;
public function __construct() {
$this->contentDataProcessor = GeneralUtility::makeInstance(ContentDataProcessor::class);
}
public function process(string $content, array $config) {
if(empty($content)) {
$content = [];
}
$titleField = $this->cObj->stdWrapValue('titleField', $config, 'header');
$tableName = $this->cObj->stdWrapValue('table', $config, 'tt_content');
$records = $this->cObj->getRecords($tableName, $config);
$processedRecordVariables = [];
foreach($records as $key => $record) {
/** @var ContentObjectRenderer $recordContentObjectRenderer */
$recordContentObjectRenderer = GeneralUtility::makeInstance(ContentObjectRenderer::class);
$recordContentObjectRenderer->start($record, $tableName);
$processedRecordVariables[$key] = ['data' => $record];
$processedRecordVariables[$key] = $this->contentDataProcessor->process($recordContentObjectRenderer, $config, $processedRecordVariables[$key]);
$content[] = [
'uid' => $record['uid'],
'title' => $record[$titleField],
// TODO: improve by using slug:
'_OVERRIDE_HREF' => 'index.php?id='.$record['pid'].'#c'.$record['uid']
];
}
return $content;
}
}