public static function Registration::baseFieldDefinitions in RNG - Events and Registrations 8
Same name and namespace in other branches
- 8.2 src/Entity/Registration.php \Drupal\rng\Entity\Registration::baseFieldDefinitions()
- 3.x src/Entity/Registration.php \Drupal\rng\Entity\Registration::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/ Registration.php, line 195
Class
- Registration
- Defines the registration entity class.
Namespace
Drupal\rng\EntityCode
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields['id'] = BaseFieldDefinition::create('integer')
->setLabel(t('Registration ID'))
->setDescription(t('The registration ID.'))
->setReadOnly(TRUE)
->setSetting('unsigned', TRUE);
$fields['uuid'] = BaseFieldDefinition::create('uuid')
->setLabel(t('UUID'))
->setDescription(t('The registration UUID.'))
->setReadOnly(TRUE);
$fields['vid'] = BaseFieldDefinition::create('integer')
->setLabel(t('Revision ID'))
->setDescription(t('The registration revision ID.'))
->setReadOnly(TRUE)
->setSetting('unsigned', TRUE);
$fields['type'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Type'))
->setDescription(t('The registration type.'))
->setSetting('target_type', 'registration_type')
->setReadOnly(TRUE);
$fields['langcode'] = BaseFieldDefinition::create('language')
->setLabel(t('Language code'))
->setDescription(t('The registration language code.'))
->setRevisionable(TRUE);
$fields['event'] = BaseFieldDefinition::create('dynamic_entity_reference')
->setLabel(t('Event'))
->setDescription(t('The event for the registration.'))
->setSetting('exclude_entity_types', 'true')
->setSetting('entity_type_ids', array(
'registrant',
'registration',
))
->setDescription(t('The relationship between this registration and an event.'))
->setRevisionable(TRUE)
->setReadOnly(TRUE);
$fields['groups'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Groups'))
->setCardinality(BaseFieldDefinition::CARDINALITY_UNLIMITED)
->setDescription(t('The groups the registration is assigned.'))
->setSetting('target_type', 'registration_group')
->addConstraint('RegistrationGroupSibling');
$fields['created'] = BaseFieldDefinition::create('created')
->setLabel(t('Authored on'))
->setDescription(t('Time the Registration was created.'))
->setTranslatable(FALSE)
->setRevisionable(FALSE);
$fields['changed'] = BaseFieldDefinition::create('changed')
->setLabel(t('Updated on'))
->setDescription(t('The time Registration was last updated.'))
->setTranslatable(TRUE)
->setRevisionable(TRUE);
return $fields;
}