使用内联元素扩展tt_content,未附加元素

时间:2018-11-26 08:56:19

标签: typo3 typo3-9.x

我在TYPO3 9.5中创建了一个扩展,用于根据tutorial将来自另一个表的多个元素添加到类型为“ inline”(IRRE)的tt_content中。

我可以在后端的content元素中添加新的内联元素,但是当我保存它们时,它们未附加到tt_content元素。但是我可以在列表视图中将它们视为记录。仅缺少两个元素之间的连接。

tt_content的附加字段的定义:

CREATE TABLE tt_content (
    tx_jrinterview_question_answer int(11) DEFAULT '0' NOT NULL
);

新记录表的定义:

CREATE TABLE tx_jrinterview_question_answer (
    parentid  int(11) DEFAULT '0' NOT NULL,
    parenttable varchar(255) DEFAULT '' NOT NULL,
    question varchar(255) DEFAULT '' NOT NULL,
    answer text
);

tt_content的TCA部分添加了IRRE功能:

'tx_jrinterview_question_answer' => [
    'exclude' => true,
        'label' => 'Questions and Answers',
        'config' => [
             'type' => 'inline',
             'allowed' => 'tx_jrinterview_question_answer',
             'foreign_table' => 'tx_jrinterview_question_answer',
             'foreign_field' => 'parentid',
             'foreign_table_field' => 'parenttable',
             'minitems' => 0,
             'maxitems' => 99,
         ],
     ],
],

以及新记录的TCA:

<?php
return [
    'ctrl' => [
        'title' => 'Question and answer',
        'label' => 'question',
        'tstamp' => 'tstamp',
        'crdate' => 'crdate',
        'cruser_id' => 'cruser_id',
        'versioningWS' => true,
        'languageField' => 'sys_language_uid',
        'transOrigPointerField' => 'l10n_parent',
        'transOrigDiffSourceField' => 'l10n_diffsource',
        'delete' => 'deleted',
        'enablecolumns' => [
            'disabled' => 'hidden',
            'starttime' => 'starttime',
            'endtime' => 'endtime',
        ],
        'searchFields' => 'question,answer',
    ],
    'interface' => [
        'showRecordFieldList' => 'parentid,parenttable,sys_language_uid, l10n_parent, l10n_diffsource, hidden, question, answer',
    ],
    'types' => [
        '0' => ['showitem' => 'parentid, parenttable, sys_language_uid, l10n_parent, l10n_diffsource, hidden, question, answer, --div--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:tabs.access, starttime, endtime'],
    ],
    'columns' => [
        'pid' => [
            'label' => 'Pid',
            'config' => [
                'type' => 'passthrough'
            ]
        ],
        'crdate' => [
            'label' => 'Crdate',
            'config' => [
                'type' => 'passthrough',
            ]
        ],
        'tstamp' => [
            'label' => 'Tstamp',
            'config' => [
                'type' => 'passthrough',
            ]
        ],
        'sys_language_uid' => [
            'exclude' => true,
            'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.language',
            'config' => [
                'type' => 'select',
                'renderType' => 'selectSingle',
                'special' => 'languages',
                'items' => [
                    [
                        'LLL:EXT:lang/locallang_general.xlf:LGL.allLanguages',
                        -1,
                        'flags-multiple'
                    ]
                ],
                'default' => 0,
            ],
        ],
        'l10n_parent' => [
            'displayCond' => 'FIELD:sys_language_uid:>:0',
            'exclude' => true,
            'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.l18n_parent',
            'config' => [
                'type' => 'select',
                'renderType' => 'selectSingle',
                'default' => 0,
                'items' => [
                    ['', 0],
                ],
                'foreign_table' => 'tx_jrinterview_question_answer',
                'foreign_table_where' => 'AND tx_jrinterview_question_answer.pid=###CURRENT_PID### AND tx_jrinterview_question_answer.sys_language_uid IN (-1,0)',
            ],
        ],
        'l10n_diffsource' => [
            'config' => [
                'type' => 'passthrough',
            ],
        ],
        't3ver_label' => [
            'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.versionLabel',
            'config' => [
                'type' => 'input',
                'size' => 30,
                'max' => 255,
            ],
        ],
        'hidden' => [
            'exclude' => true,
            'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.hidden',
            'config' => [
                'type' => 'check',
                'items' => [
                    '1' => [
                        '0' => 'LLL:EXT:lang/locallang_core.xlf:labels.enabled'
                    ]
                ],
            ],
        ],
        'starttime' => [
            'exclude' => true,
            'behaviour' => [
                'allowLanguageSynchronization' => true
            ],
            'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.starttime',
            'config' => [
                'type' => 'input',
                'renderType' => 'inputDateTime',
                'size' => 13,
                'eval' => 'datetime',
                'default' => 0,
            ],
        ],
        'endtime' => [
            'exclude' => true,
            'behaviour' => [
                'allowLanguageSynchronization' => true
            ],
            'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.endtime',
            'config' => [
                'type' => 'input',
                'renderType' => 'inputDateTime',
                'size' => 13,
                'eval' => 'datetime',
                'default' => 0,
                'range' => [
                    'upper' => mktime(0, 0, 0, 1, 1, 2038)
                ],
            ],
        ],

        'parentid' => [
            'exclude' => true,
            'label' => 'parentid',
            'config' => [
                'type' => 'passthrough',
            ],
        ],
        'parenttable' => [
            'exclude' => true,
            'label' => 'parenttable',
            'config' => [
                'type' => 'passthrough',
            ],
        ],
        'question' => [
            'exclude' => true,
            'label' => 'question',
            'config' => [
                'type' => 'input',
                'size' => 30,
                'eval' => 'trim'
            ],
        ],
        'answer' => [
            'exclude' => true,
            'label' => 'answer',
            'config' => [
                'type' => 'text',
                'cols' => 40,
                'rows' => 15,
                'eval' => 'trim'
            ]
        ],

    ],
];

也许这与语言有关?如果通过IRRE创建后直接在表中更改了parentid和parenttable,则会显示该记录。

1 个答案:

答案 0 :(得分:0)

向您的问题/答案表添加更多字段。 在您的ext_tables.sql

CREATE TABLE tx_jrinterview_question_answer (
    uid int(11) NOT NULL auto_increment,
    pid int(11) DEFAULT '0' NOT NULL,
    tstamp int(11) DEFAULT '0' NOT NULL,
    crdate int(11) DEFAULT '0' NOT NULL,
    cruser_id int(11) DEFAULT '0' NOT NULL,
    deleted tinyint(4) DEFAULT '0' NOT NULL,
    hidden tinyint(4) DEFAULT '0' NOT NULL,

    parentid  int(11) DEFAULT '0' NOT NULL,
    parenttable varchar(255) DEFAULT '' NOT NULL,
    question varchar(255) DEFAULT '' NOT NULL,
    answer text,

    PRIMARY KEY (uid),
    KEY parent (pid)
);

在您的Configuration / TCA / tx_jrinterview_question_answer.php

<?php
defined('TYPO3_MODE') or die();

return [
    'ctrl' => [
        'title' => 'tx_jrinterview_question_answer',
        'label' => 'question',
        'tstamp' => 'tstamp',
        'crdate' => 'crdate',
        'cruser_id' => 'cruser_id',
        'delete' => 'deleted',
        'enablecolumns' => [
            'disabled' => 'hidden',
        ],
    ],
    'interface' => [
        'showRecordFieldList' => 'parentid,parenttable,question,answer'
    ],
    'columns' => [
        'pid' => [
            'label' => 'Pid',
            'config' => [
                'type' => 'passthrough'
            ]
        ],
        'crdate' => [
            'label' => 'Crdate',
            'config' => [
                'type' => 'passthrough',
            ]
        ],
        'tstamp' => [
            'label' => 'Tstamp',
            'config' => [
                'type' => 'passthrough',
            ]
        ],
        'hidden' => [
            'exclude' => true,
            'label' => 'Hidden',
            'config' => [
                'type' => 'check',
                'default' => 0
            ]
        ],
        'parentid' => [
            'exclude' => true,
            'label' => 'Parentid',
            'config' => [
                'type' => 'passthrough',
            ],
        ],
        'parenttable' => [
            'exclude' => true,
            'label' => 'Parenttable',
            'config' => [
                'type' => 'passthrough',
            ],
        ],
        'question' => [
            'exclude' => true,
            'label' => 'Question',
            'config' => [
                'type' => 'input',
                'size' => 30,
                'eval' => 'trim'
            ],
        ],
        'answer' => [
            'exclude' => true,
            'label' => 'Answer',
            'config' => [
                'type' => 'text',
                'cols' => 40,
                'rows' => 15,
                'eval' => 'trim'
            ]
        ],
    ],
    'types' => [
        0 => [
            'showitem' => 'parentid,parenttable,question,answer'
        ]
    ]
];

连接应该保持。我做了测试。