Typo3 6.2 Extension如何实现继承?
How to realize inheritance in Typo3 6.2 Extension?
我的目标是能够:
- 在后端创建
Expertise
个条目(已完成)
- 在后端创建
SubExpertise
个条目
- (与
Expertise
相同的道具,但
他们属于一个或多个 Expertise
)
- 在后端创建
AdditionalInfoTitles
个条目
- (它们可以属于一个或多个
Expertise
或 SubExpertise
)
- 我希望在创建新条目时能够从所有
Expertise
和 SubExpertise
中选择对象
现在我只能在所有 Expertise
- 条目中进行选择:
这就是我考虑继承的原因,因为那时 SubExpertise
与 Expertise
属于同一类型,因此会自动显示在 Expertise
列表中的 AdditionalInfoTitles
条目中.但这只是我的理论,我有点被 typo3 TCA 和我缺乏的其他知识困在现实中......
在我的扩展构建器中,我做了以下操作(不要介意 subExpertises 属性)
然后我将 expertise
添加到 Overrides
文件夹,因为我试图用 subexpertise
:
扩展它
<?php
if (!defined('TYPO3_MODE')) {
die ('Access denied.');
}
$temporaryColumns = array (
'expertise' => array(
'exclude' => 1,
'label' => 'LLL:EXT:appoints/Resources/Private/Language/locallang_db.xlf:tx_appoints_domain_model_subexpertise.expertise',
'config' => array(
'type' => 'select',
'foreign_table' => 'tx_appoints_domain_model_subexpertise',
'MM' => 'tx_appoints_subexpertise_expertise_mm',
'size' => 10,
'autoSizeMax' => 30,
'maxitems' => 9999,
'multiple' => 0,
'wizards' => array(
'_PADDING' => 1,
'_VERTICAL' => 1,
'edit' => array(
'module' => array(
'name' => 'wizard_edit',
),
'type' => 'popup',
'title' => 'Edit',
'icon' => 'edit2.gif',
'popup_onlyOpenIfSelected' => 1,
'JSopenParams' => 'height=350,width=580,status=0,menubar=0,scrollbars=1',
),
'add' => Array(
'module' => array(
'name' => 'wizard_add',
),
'type' => 'script',
'title' => 'Create new',
'icon' => 'add.gif',
'params' => array(
'table' => 'tx_appoints_domain_model_expertise',
'pid' => '###CURRENT_PID###',
'setValue' => 'prepend'
),
),
),
),
),
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
'tx_appoints_domain_model_expertise',
$temporaryColumns
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes(
'tx_appoints_domain_model_expertise',
'expertise'
);
但我认为我的方向不对 -
因为我认为这样我将无法在后端与 Expertise
分开添加 SubExpertise
- 我已经对扩展 fe_user
的对象有同样的问题,因为当创建它们我通常必须通过一个新用户然后设置扩展类型 - 但这样我就没有扩展 fe_user
.
的不同实体的单独列表
我会在很大程度上摆脱 Expertise 和 SubExpertise 之间的分离。根据您的描述,一个 SubExpertise 不能将另一个 SubExpertise 作为其父级,因此您可以调整 select 字段,使其仅列出父级字段为空的 Expertises。
通过消除差异,selecting (Sub)Expertise's in AdditionalInfoTitles 的问题被消除;它只是一个相同类型的对象。
如果您需要在 BE 表单中进行区分,有很多选项可以调整所列项目的标签,使用您自己的功能来构建列表,甚至是自定义表单元素。
在 Extbase 中,您可以简单地在存储库中编写一些函数来获取 Expertise、SubExpertise 或两者。
如果实体 SubExpertise
在您的域模型中没有意义,Jigal 的答案非常适合您的场景。如果它确实有意义,您可以在 Extbase 中使用单个 table 继承来实现。
class Expertise extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
{
// all common properties
}
class SubExpertise extends Expertise
{
/**
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\[YourVendorName]\Appoints\Domain\Model\Expertise>
*/
protected $expertises;
public function __construct()
{
$this->expertises = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
}
public function getExpertises() {}
public function setExpertises($expertises) {}
}
通过 TypoScript 然后你必须定义映射规则,因为 Expertise
和 SubExpertise
将存储在相同的 table tx_appoints_domain_model_subexpertise
.
您将在 Extbase book 中找到有关单个 table 继承的更多详细信息。
我的目标是能够:
- 在后端创建
Expertise
个条目(已完成) - 在后端创建
SubExpertise
个条目- (与
Expertise
相同的道具,但 他们属于一个或多个Expertise
)
- (与
- 在后端创建
AdditionalInfoTitles
个条目- (它们可以属于一个或多个
Expertise
或SubExpertise
) - 我希望在创建新条目时能够从所有
Expertise
和SubExpertise
中选择对象
- (它们可以属于一个或多个
现在我只能在所有 Expertise
- 条目中进行选择:
这就是我考虑继承的原因,因为那时 SubExpertise
与 Expertise
属于同一类型,因此会自动显示在 Expertise
列表中的 AdditionalInfoTitles
条目中.但这只是我的理论,我有点被 typo3 TCA 和我缺乏的其他知识困在现实中......
在我的扩展构建器中,我做了以下操作(不要介意 subExpertises 属性)
然后我将 expertise
添加到 Overrides
文件夹,因为我试图用 subexpertise
:
<?php
if (!defined('TYPO3_MODE')) {
die ('Access denied.');
}
$temporaryColumns = array (
'expertise' => array(
'exclude' => 1,
'label' => 'LLL:EXT:appoints/Resources/Private/Language/locallang_db.xlf:tx_appoints_domain_model_subexpertise.expertise',
'config' => array(
'type' => 'select',
'foreign_table' => 'tx_appoints_domain_model_subexpertise',
'MM' => 'tx_appoints_subexpertise_expertise_mm',
'size' => 10,
'autoSizeMax' => 30,
'maxitems' => 9999,
'multiple' => 0,
'wizards' => array(
'_PADDING' => 1,
'_VERTICAL' => 1,
'edit' => array(
'module' => array(
'name' => 'wizard_edit',
),
'type' => 'popup',
'title' => 'Edit',
'icon' => 'edit2.gif',
'popup_onlyOpenIfSelected' => 1,
'JSopenParams' => 'height=350,width=580,status=0,menubar=0,scrollbars=1',
),
'add' => Array(
'module' => array(
'name' => 'wizard_add',
),
'type' => 'script',
'title' => 'Create new',
'icon' => 'add.gif',
'params' => array(
'table' => 'tx_appoints_domain_model_expertise',
'pid' => '###CURRENT_PID###',
'setValue' => 'prepend'
),
),
),
),
),
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
'tx_appoints_domain_model_expertise',
$temporaryColumns
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes(
'tx_appoints_domain_model_expertise',
'expertise'
);
但我认为我的方向不对 -
因为我认为这样我将无法在后端与 Expertise
分开添加 SubExpertise
- 我已经对扩展 fe_user
的对象有同样的问题,因为当创建它们我通常必须通过一个新用户然后设置扩展类型 - 但这样我就没有扩展 fe_user
.
我会在很大程度上摆脱 Expertise 和 SubExpertise 之间的分离。根据您的描述,一个 SubExpertise 不能将另一个 SubExpertise 作为其父级,因此您可以调整 select 字段,使其仅列出父级字段为空的 Expertises。 通过消除差异,selecting (Sub)Expertise's in AdditionalInfoTitles 的问题被消除;它只是一个相同类型的对象。
如果您需要在 BE 表单中进行区分,有很多选项可以调整所列项目的标签,使用您自己的功能来构建列表,甚至是自定义表单元素。
在 Extbase 中,您可以简单地在存储库中编写一些函数来获取 Expertise、SubExpertise 或两者。
如果实体 SubExpertise
在您的域模型中没有意义,Jigal 的答案非常适合您的场景。如果它确实有意义,您可以在 Extbase 中使用单个 table 继承来实现。
class Expertise extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
{
// all common properties
}
class SubExpertise extends Expertise
{
/**
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\[YourVendorName]\Appoints\Domain\Model\Expertise>
*/
protected $expertises;
public function __construct()
{
$this->expertises = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
}
public function getExpertises() {}
public function setExpertises($expertises) {}
}
通过 TypoScript 然后你必须定义映射规则,因为 Expertise
和 SubExpertise
将存储在相同的 table tx_appoints_domain_model_subexpertise
.
您将在 Extbase book 中找到有关单个 table 继承的更多详细信息。