[TYPO3-dev] EXTBASE :: Domain model inheritance for entities
Philipp
philippwrann at gmx.at
Wed Aug 14 15:27:10 CEST 2013
Write question as a superclass and define it as superclass via typoscript. Now you can add 3 types to your TCA and set that types field as recordType via TA (extbase config for your question model). Each type is then connected to a model which just extends the question model.
Some more specific chunks:
[TCA]
$TCA['tx_extension_domain_model_question'] = array (
'ctrl' => array (
'type' => 'type',
)
);
That type is a TCA select field which holds your options:
Type 1: multiple
Type 2: text
Type 3: assignment
[Typoscript:]
config.tx_extbase.persistence.classes {
Vendor\Extension\Domain\Model\Question {
subclasses {
Vendor\Extension\Domain\Model\MultipleChoiceQuestion = Vendor\Extension\Domain\Model\MultipleChoiceQuestion
Vendor\Extension\Domain\Model\TextInputQuestion = Vendor\Extension\Domain\Model\TextInputQuestion
Vendor\Extension\Domain\Model\AssignmentQuestion = Vendor\Extension\Domain\Model\AssignmentQuestion
}
}
Vendor\Extension\Domain\Model\MultipleChoiceQuestion {
mapping {
tableName = tx_extension_domain_model_question
recordType = multiple
}
}
Vendor\Extension\Domain\Model\TextInputQuestion {
mapping {
tableName = tx_extension_domain_model_question
recordType = text
}
}
Vendor\Extension\Domain\Model\AssignmentQuestion {
mapping {
tableName = tx_extension_domain_model_question
recordType = assignment
}
}
}
Now you can request all types of questions via a QuestionRepository or only specifics via a MultipleChoiceQuestionRepository
Your entity property in quiz would be like
/**
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Vendor\Extension\Domain\Model\Question>
* @lazy
* @cascade remove
*/
protected $questions;
More information about the TYPO3-dev
mailing list