public static function QuizResultAnswer::baseFieldDefinitions in Quiz 8.6
Same name and namespace in other branches
- 8.5 src/Entity/QuizResultAnswer.php \Drupal\quiz\Entity\QuizResultAnswer::baseFieldDefinitions()
- 6.x src/Entity/QuizResultAnswer.php \Drupal\quiz\Entity\QuizResultAnswer::baseFieldDefinitions()
Provides base field definitions for an entity type.
Implementations typically use the class \Drupal\Core\Field\BaseFieldDefinition for creating the field definitions; for example a 'name' field could be defined as the following:
$fields['name'] = BaseFieldDefinition::create('string')
->setLabel(t('Name'));
By definition, base fields are fields that exist for every bundle. To provide definitions for fields that should only exist on some bundles, use \Drupal\Core\Entity\FieldableEntityInterface::bundleFieldDefinitions().
The definitions returned by this function can be overridden for all bundles by hook_entity_base_field_info_alter() or overridden on a per-bundle basis via 'base_field_override' configuration entities.
Parameters
\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type definition. Useful when a single class is used for multiple, possibly dynamic entity types.
Return value
\Drupal\Core\Field\FieldDefinitionInterface[] An array of base field definitions for the entity type, keyed by field name.
Overrides ContentEntityBase::baseFieldDefinitions
See also
\Drupal\Core\Entity\EntityFieldManagerInterface::getFieldDefinitions()
\Drupal\Core\Entity\FieldableEntityInterface::bundleFieldDefinitions()
File
- src/
Entity/ QuizResultAnswer.php, line 56
Class
- QuizResultAnswer
- Defines the Quiz entity class.
Namespace
Drupal\quiz\EntityCode
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields = parent::baseFieldDefinitions($entity_type);
$fields['result_id'] = BaseFieldDefinition::create('entity_reference')
->setSetting('target_type', 'quiz_result')
->setLabel('Quiz result ID');
$fields['type'] = BaseFieldDefinition::create('string')
->setLabel('Answer type');
$fields['question_id'] = BaseFieldDefinition::create('entity_reference')
->setSetting('target_type', 'quiz_question')
->setLabel('Question ID');
$fields['question_vid'] = BaseFieldDefinition::create('integer')
->setLabel('Question revision ID');
$fields['tid'] = BaseFieldDefinition::create('entity_reference')
->setLabel('Taxonomy term');
$fields['is_correct'] = BaseFieldDefinition::create('boolean')
->setLabel('Correct');
$fields['is_skipped'] = BaseFieldDefinition::create('boolean')
->setLabel('Skipped');
$fields['points_awarded'] = BaseFieldDefinition::create('integer')
->setLabel('Scaled points awarded');
$fields['answer_timestamp'] = BaseFieldDefinition::create('timestamp')
->setLabel('Date answered');
$fields['number'] = BaseFieldDefinition::create('integer')
->setLabel('Question number');
$fields['display_number'] = BaseFieldDefinition::create('integer')
->setLabel('Display number');
$fields['is_doubtful'] = BaseFieldDefinition::create('boolean')
->setLabel('Doubtful');
$fields['created'] = BaseFieldDefinition::create('created')
->setLabel('Created');
$fields['changed'] = BaseFieldDefinition::create('changed')
->setLabel('Changed');
$fields['is_evaluated'] = BaseFieldDefinition::create('boolean')
->setDefaultValue(1)
->setLabel('Evaluated');
$fields['answer_feedback'] = BaseFieldDefinition::create('text_long')
->setLabel(t('Answer feedback'))
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE)
->setDisplayOptions('form', [
'type' => 'text_textarea',
]);
return $fields;
}