几天前我开始使用TYPO3 8.7.7,我创建了一个使用Fluid供电TYPO3扩展的小型网站 . 现在我想创建一个自定义内容元素,显示编辑器可以在后端管理的一些产品 . 在我的扩展中,我为产品创建了一个简单的模型:
namespace Something\Products\Domain\Model;
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
class Product extends AbstractEntity
{
protected $name;
protected $description;
public function __construct(string $name, string $description)
{ ... }
public function getName(): string
{ ... }
public function setName(string $name)
{ ... }
public function getDescription(): string
{ ... }
public function setDescription(string $description)
{ ... }
}
我还创建了一个ProductRepository类,它只扩展了\ TYPO3 \ CMS \ Extbase \ Persistence \ Repository .
在EXT中:something / Configuration / TCA / tx_product.php
我有以下定义:
return [
'ctrl' => [
'title' => 'Products',
'label' => 'name'
],
'columns' => [
'name' => [
'label' => 'Name',
'config' => [
'type' => 'input',
'eval' => 'trim,required',
],
],
'description' => [
'label' => 'Description',
'config' => [
'type' => 'text',
'eval' => 'trim,required',
],
],
],
'types' => [
'0' => ['showitem' => 'name, description'],
],
];
添加和编辑产品在Web-> List Module中运行良好 . 我将它们存储在名为Products的页面树中的文件夹中 .
我的目标是在任意列中创建名为Products的内容元素到页面 . 前端中的模板应显示产品列表 .
在我的EXT中我会期待这样的东西:something / Resources / Private / Template / Content / Product.html
<div xmlns="http://www.w3.org/1999/xhtml" lang="en"
xmlns:f="http://typo3.org/ns/TYPO3/Fluid/ViewHelpers"
xmlns:flux="http://typo3.org/ns/FluidTYPO3/Flux/ViewHelpers"
xmlns:v="http://typo3.org/ns/FluidTYPO3/Vhs/ViewHelpers">
<f:layout name="Content"/>
<f:section name="Configuration">
<flux:form id="newsitem" options="{group: 'Unicontrol'}">
<flux:field.input name="settings.headline" required="true"/>
</flux:form>
</f:section>
<f:section name="Main">
<ul>
<f:for each="{products}" as="product">
<li>{product.name}</li>
</f:for>
</ul>
</f:section>
</div>
现在我不知道如何做到这一点 . 我想我需要一个控制器类,但我无法弄清楚如何将它与我的Fluid TYPO3模板/ Partials连接 . 任何人都可以帮我找到实现这个目标的方法吗?
在此先感谢您,祝您度过愉快的一天 .
EDIT:
我现在的CE模板现在看起来像这样:
<div xmlns="http://www.w3.org/1999/xhtml" lang="en"
xmlns:f="http://typo3.org/ns/TYPO3/Fluid/ViewHelpers"
xmlns:flux="http://typo3.org/ns/FluidTYPO3/Flux/ViewHelpers"
xmlns:v="http://typo3.org/ns/FluidTYPO3/Vhs/ViewHelpers">
<f:layout name="Content"/>
<f:section name="Configuration">
<flux:form id="products" options="{group: 'Unicontrol'}">
<flux:field.relation name="settings.relation" table="tx_products_domain_model_product"
transform="TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage<Something\\Products\\Domain\\Model\\Product>"
multiple="true"/>
</flux:form>
</f:section>
<f:section name="Main">
<ul>
<f:for each="{settings.relation}" as="product">
<li>{product.name}</li>
</f:for>
</ul>
</f:section>
</div>
我现在可以在CE中选择我的列表中的一个产品,但是在前端它只显示一个元素,即我在后端选择的元素 . 如果我逃避斜线并不重要 .
1 回答
通常你更喜欢有一个实际的插件 - 有几个原因,但最重要的是,它将你的内容与交互式插件分开,并为每个插件提供一个专用的参数范围等 .
也就是说,您可以将产品列表显示为启用Flux的元素 . 它需要三件事:
您的模型的存储库必须存在(或者它不被视为聚合根 . 一个"Product"肯定听起来像聚合根,所以很适合!
在内容元素模板中添加
flux:field.relation
或.select
或.multiRelation
,具体取决于您希望如何处理选择 . 将此指向域模型的SQL表(有关进一步参数的详细信息,请参阅Flux ViewHelper文档以指定选择的完成方式)使用该ViewHelper的
transform
参数声明最终类型应为TYPO3\CMS\Extbase\Persistence\ObjectStorage<Your\Model\ClassName>
(请注意,您可能需要转义反斜杠,例如TYPO3\\CMS\\...
) .然后渲染产品列表,就像您在模板的
Main
部分中一样 . 内部磁通转换在字段中选择的任何值或关系,读取UID列表并使用您创建的存储库来选择每个 .