function ContentEntityBase::baseFieldDefinitions
Same name in other branches
- 9 core/lib/Drupal/Core/Entity/ContentEntityBase.php \Drupal\Core\Entity\ContentEntityBase::baseFieldDefinitions()
- 8.9.x core/lib/Drupal/Core/Entity/ContentEntityBase.php \Drupal\Core\Entity\ContentEntityBase::baseFieldDefinitions()
- 10 core/lib/Drupal/Core/Entity/ContentEntityBase.php \Drupal\Core\Entity\ContentEntityBase::baseFieldDefinitions()
13 calls to ContentEntityBase::baseFieldDefinitions()
- Comment::baseFieldDefinitions in core/
modules/ comment/ src/ Entity/ Comment.php - ContentModerationState::baseFieldDefinitions in core/
modules/ content_moderation/ src/ Entity/ ContentModerationState.php - EditorialContentEntityBase::baseFieldDefinitions in core/
lib/ Drupal/ Core/ Entity/ EditorialContentEntityBase.php - EntityTest::baseFieldDefinitions in core/
modules/ system/ tests/ modules/ entity_test/ src/ Entity/ EntityTest.php - EntityTestWithBundle::baseFieldDefinitions in core/
modules/ system/ tests/ modules/ entity_test/ src/ Entity/ EntityTestWithBundle.php
16 methods override ContentEntityBase::baseFieldDefinitions()
- Comment::baseFieldDefinitions in core/
modules/ comment/ src/ Entity/ Comment.php - ContentModerationState::baseFieldDefinitions in core/
modules/ content_moderation/ src/ Entity/ ContentModerationState.php - EditorialContentEntityBase::baseFieldDefinitions in core/
lib/ Drupal/ Core/ Entity/ EditorialContentEntityBase.php - EntityTest::baseFieldDefinitions in core/
modules/ system/ tests/ modules/ entity_test/ src/ Entity/ EntityTest.php - EntityTestUpdate::baseFieldDefinitions in core/
modules/ system/ tests/ modules/ entity_test_update/ src/ Entity/ EntityTestUpdate.php
File
-
core/
lib/ Drupal/ Core/ Entity/ ContentEntityBase.php, line 1362
Class
- ContentEntityBase
- Implements Entity Field API specific enhancements to the Entity class.
Namespace
Drupal\Core\EntityCode
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields = [];
if ($entity_type->hasKey('id')) {
$fields[$entity_type->getKey('id')] = BaseFieldDefinition::create('integer')->setLabel(new TranslatableMarkup('ID'))
->setReadOnly(TRUE)
->setSetting('unsigned', TRUE);
}
if ($entity_type->hasKey('uuid')) {
$fields[$entity_type->getKey('uuid')] = BaseFieldDefinition::create('uuid')->setLabel(new TranslatableMarkup('UUID'))
->setReadOnly(TRUE);
}
if ($entity_type->hasKey('revision')) {
$fields[$entity_type->getKey('revision')] = BaseFieldDefinition::create('integer')->setLabel(new TranslatableMarkup('Revision ID'))
->setReadOnly(TRUE)
->setSetting('unsigned', TRUE);
}
if ($entity_type->hasKey('langcode')) {
$fields[$entity_type->getKey('langcode')] = BaseFieldDefinition::create('language')->setLabel(new TranslatableMarkup('Language'))
->setDisplayOptions('view', [
'region' => 'hidden',
])
->setDisplayOptions('form', [
'type' => 'language_select',
'weight' => 2,
]);
if ($entity_type->isRevisionable()) {
$fields[$entity_type->getKey('langcode')]
->setRevisionable(TRUE);
}
if ($entity_type->isTranslatable()) {
$fields[$entity_type->getKey('langcode')]
->setTranslatable(TRUE);
}
}
if ($entity_type->hasKey('bundle')) {
if ($bundle_entity_type_id = $entity_type->getBundleEntityType()) {
$fields[$entity_type->getKey('bundle')] = BaseFieldDefinition::create('entity_reference')->setLabel($entity_type->getBundleLabel())
->setSetting('target_type', $bundle_entity_type_id)
->setRequired(TRUE)
->setReadOnly(TRUE);
}
else {
$fields[$entity_type->getKey('bundle')] = BaseFieldDefinition::create('string')->setLabel($entity_type->getBundleLabel())
->setRequired(TRUE)
->setReadOnly(TRUE);
}
}
return $fields;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.