You are here

public static function QuizQuestionRelationship::baseFieldDefinitions in Quiz 6.x

Same name and namespace in other branches
  1. 8.6 src/Entity/QuizQuestionRelationship.php \Drupal\quiz\Entity\QuizQuestionRelationship::baseFieldDefinitions()
  2. 8.5 src/Entity/QuizQuestionRelationship.php \Drupal\quiz\Entity\QuizQuestionRelationship::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/QuizQuestionRelationship.php, line 49

Class

QuizQuestionRelationship
Defines the Quiz entity class.

Namespace

Drupal\quiz\Entity

Code

public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
  $fields = parent::baseFieldDefinitions($entity_type);
  $fields['qqr_pid'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel('Question parent')
    ->setSettings([
    'target_type' => 'quiz_question_relationship',
  ]);
  $fields['quiz_id'] = BaseFieldDefinition::create('entity_reference')
    ->setSettings([
    'target_type' => 'quiz',
  ])
    ->setLabel(t('Quiz'));
  $fields['quiz_vid'] = BaseFieldDefinition::create('integer')
    ->setLabel('Quiz revision ID');
  $fields['question_id'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel('Question ID')
    ->setSettings([
    'target_type' => 'quiz_question',
  ]);
  $fields['question_vid'] = BaseFieldDefinition::create('integer')
    ->setLabel('Question revision ID');
  $fields['question_status'] = BaseFieldDefinition::create('integer')
    ->setDefaultValue(QuizQuestion::QUESTION_ALWAYS)
    ->setLabel('Question status');
  $fields['weight'] = BaseFieldDefinition::create('integer')
    ->setLabel('Weight')
    ->setDefaultValue(0);
  $fields['max_score'] = BaseFieldDefinition::create('integer')
    ->setLabel('Calculated max score');
  $fields['auto_update_max_score'] = BaseFieldDefinition::create('boolean')
    ->setLabel('Automatically update max score')
    ->setDefaultValue(TRUE);
  return $fields;
}