TYPO3 9 Extbase:编辑 m:n 来自后端表单中父元素和子元素的关系

TYPO3 9 Extbase: edit m:n relation from both parent and child elements in backend form

在我的扩展中,我有两个模型:父模型是博士课程的研究组子模型正在申请轮次(有开始和结束日期)。在中间table我存储关系参与申请轮次的研究小组介于两者之间。申请轮次可以与参加两个平行轮次的某些组重叠。这就是为什么我需要使它成为 m:n 关系的原因。我使用 official documentation.

完成了所有工作

虽然我可以在研究小组表格中 select 多个申请轮次,但我还想让申请轮次的后端表格显示 select 来自的所有小组的列表。

我发现 information on inline fields 显示双向使用 - 但我正在努力将其转化为我的扩展程序的情况。

注意:我不想进行内联编辑,真的只是select两边的CheckBox列表。

Groups 域模型包含以下 属性:

/**
 * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Myvendor\Researchgroups\Domain\Model\ApplicationRounds>
 */
protected $applicationRounds = NULL;

application_rounds INT(10)

保存在数据库中

Groups TCA 包含以下定义:

$GLOBALS['TCA']['tx_researchgroups_domain_model_groups']['columns'] = [
    'application_rounds' => [
        'label' => '' . $locLang . 'groups.recruitingSelection',
        'config' => [
            'type' => 'select',
            'renderType' => 'selectCheckBox',
            'foreign_table' => 'tx_researchgroups_domain_model_applicationrounds',
            'foreign_table_where' => 'ORDER BY tx_researchgroups_domain_model_applicationrounds.date_open DESC',
            'MM' => 'tx_researchgroups_groups_applicationrounds_mm',
            'eval' => 'int',
        ],
    ],
]

如何将相应的 select 列表添加到 ApplicationRounds 模型?我是否也必须在那里添加一个 属性 并保存在数据库中 – 即使我认为那是多余的?

你需要设置mm-opposite-field:

If you want to make a MM relation editable from the foreign side (bidirectional) of the relation as well, you need to set MM_opposite_field on the foreign side to the field name on the local side.

[原发问者编辑]请参阅以获取基于此答案的完整代码

这是我根据 Bernd’s 中的提示添加的完整工作代码:

ApplicationRounds TCA(童模)

$GLOBALS['TCA']['tx_researchgroups_domain_model_applicationrounds']['columns'] = [
    'researchgroups' => [
        'label' => '' . $locLang . 'researchgroups_applicationrounds.recruitingGl',
        'config' => [
            'type' => 'select',
            'renderType' => 'selectCheckBox',
            'foreign_table' => 'tx_researchgroups_domain_model_groups',
            'foreign_table_where' => ' AND tx_researchgroups_domain_model_groups.hidden = 0 ORDER BY tx_researchgroups_domain_model_groups.last_name ASC',
            'MM' => 'tx_researchgroups_groups_applicationrounds_mm',
            'MM_opposite_field' => 'last_name',
            'eval' => 'int',
        ],
    ],
]

(不要忘记将 researchgroups 添加到 $GLOBALS['TCA']['tx_researchgroups_domain_model_applicationrounds']['types'][1]

并在子模型的数据库table中添加一个字段: researchgroups INT(11) NOT NULL DEFAULT '0',

虽然我没有将 researchgroups 添加到领域模型。