简体   繁体   English

TYPO3 - 将自定义内容元素数据存储在自己的数据库表中

[英]TYPO3 - store custom content element data in own database table

I want to create custom content elements.我想创建自定义内容元素。 I know how this works basically.我知道这基本上是如何工作的。 But I asking myself, if there is a way to store the configuration data of this elements in a decent database table?但是我问自己,是否有办法将这些元素的配置数据存储在一个像样的数据库表中?

I only know the way to extend the tt_content table and store my data there.我只知道扩展tt_content表并将我的数据存储在那里的方法。 But with a bigger amount of elements and fields the tt_content would be become bigger and bigger too.但是随着元素和字段数量的增加, tt_content也会变得越来越大。 I would like to prevent this.我想防止这种情况。

And just before you ask: I don't want to use FluidTYPO3.就在你问之前:我不想使用 FluidTYPO3。 ;) I just would like to do it with basic TYPO3 functionality. ;) 我只想用基本的 TYPO3 功能来做。

Don't know if there is a nicer way, but maybe you can create your elements with no field definition but with IRRE and min:1 and max:1 - but this is not really a nice way.不知道是否有更好的方法,但也许您可以创建没有字段定义但使用 IRRE 和 min:1 和 max:1 的元素 - 但这并不是一个很好的方法。 The better way is to reuse the fields given in tt_content as often as possible and only add more fields if really needed.更好的方法是尽可能多地重用 tt_content 中给出的字段,并且仅在确实需要时才添加更多字段。 Maybe you should have a look on EXT:mask and EXT:mask_export - those two are very powerful tools to create custom content elements (EXT:mask) and export them as an own extension (EXT:mask_export) so there is no need for these two extensions in production but only in development.也许您应该看看 EXT:mask 和 EXT:mask_export - 这两个是创建自定义内容元素 (EXT:mask) 并将它们导出为自己的扩展 (EXT:mask_export) 的非常强大的工具,因此不需要这些生产中的两个扩展,但仅在开发中。

As you create a content element you will always need to use the database table tt_content .创建内容元素时,您将始终需要使用数据库表tt_content Of course it makes sense to use relations to custom records, eg if you create elements like tabs, accordions, ...当然,使用与自定义记录的关系是有意义的,例如,如果您创建标签、手风琴等元素...

What you can do is to reuse existing columns as there are - as you said - a lot of those.您可以做的是重用现有的列,正如您所说的那样,其中有很多列。 So reuse fields like header , bodytext , image , ... Take a look at /sysext/frontend/Configuration/TCA/tt_content.php .所以重用headerbodytextimage等字段......看看/sysext/frontend/Configuration/TCA/tt_content.php The benefits are好处是

  • a bit smaller table which is most of the time not really relevant to performance一个小一点的表,大部分时间与性能无关
  • well designed fields including a label whith translations into all languages精心设计的字段,包括可翻译成所有语言的标签

You can also reuse a field and its configuration and override it with overrideChildTca .您也可以重用场及其配置和覆盖它overrideChildTca See https://docs.typo3.org/typo3cms/TCAReference/ColumnsConfig/Properties/InlineOverrideChildTCa.html?highlight=overridechildtca in the docs.请参阅文档中的https://docs.typo3.org/typo3cms/TCAReference/ColumnsConfig/Properties/InlineOverrideChildTCa.html?highlight=overridechildtca

I recommend you to have a look at the typo3 extension mask .我建议你看看typo3 扩展掩码 You can create custom contents and map existing tt_content fields to your new elements.您可以创建自定义内容并将现有 tt_content 字段映射到新元素。 It makes sense to reuse the header, bodytext, media, image fields because the backend preview will adopt automatically.重用标题、正文、媒体、图像字段是有意义的,因为后端预览将自动采用。

I used it recently and it works really nice!我最近使用它,它的效果非常好! Here is some resource to jump in (only german) 这里有一些资源可以加入(只有德语)

If you do not need to have indexes on your new fields it is not a big problem to blow up tt_content with new fields.如果您不需要在新字段上建立索引,那么用新字段炸毁 tt_content 并不是什么大问题。 It does not impact the performance so much.它不会对性能产生太大影响。

If you need to have new 1:N relations from your content to some child-record (accordion, team-listing, etc), simply add them as inline elements (IRRE) and add the field to your types-string .如果您需要从您的内容到某些子记录(手风琴、团队列表等)拥有新的 1:N 关系,只需将它们添加为内联元素(IRRE) 并将该字段添加到您的types-string

If you need to have a new kind of data, that should be filterable, sortable and so on, you should create a new type of record with its own table structure and use extbase plugins to display that data.如果你需要一种新的数据,它应该是可过滤的、可排序的等等,你应该创建一种具有自己表结构的新记录类型,并使用 extbase 插件来显示该数据。

As long as you simply need custom contents, you are fine with extending/remapping tt_content.只要您只需要自定义内容,就可以扩展/重新映射 tt_content。

You can use hooks for this.您可以为此使用钩子。

In your ext_localconf.php:在你的 ext_localconf.php 中:

$GLOBALS ['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'][] = \Namespace\Hooks\Classname::class;

And in Classes/Hooks/Classname:在类/钩子/类名中:

<?php

namespace Namespace\Hooks;

use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\DataHandling\DataHandler;

class Classname implements SingletonInterface {

    public function processDatamap_beforeStart(&$dataHandler) {
        $datamap = &$dataHandler->datamap;
    }
}

Here you have to modify the $datamap to your needs.在这里,您必须根据需要修改 $datamap。 Documentation is here: https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/Typo3CoreEngine/Database/Index.html文档在这里: https : //docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/Typo3CoreEngine/Database/Index.html

Kind regards亲切的问候

这里解释了https://learn-typo3.com/blog/news-detail/how-to-create-custom-content-elements-on-typo3 ,但是我更喜欢扩展和重用 tt_content 字段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM