function RevisionLogEntityTrait::revisionLogBaseFieldDefinitions
Same name in other branches
- 8.9.x core/lib/Drupal/Core/Entity/RevisionLogEntityTrait.php \Drupal\Core\Entity\RevisionLogEntityTrait::revisionLogBaseFieldDefinitions()
- 10 core/lib/Drupal/Core/Entity/RevisionLogEntityTrait.php \Drupal\Core\Entity\RevisionLogEntityTrait::revisionLogBaseFieldDefinitions()
- 11.x core/lib/Drupal/Core/Entity/RevisionLogEntityTrait.php \Drupal\Core\Entity\RevisionLogEntityTrait::revisionLogBaseFieldDefinitions()
Provides revision-related base field definitions for an entity type.
Parameters
\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type definition.
Return value
\Drupal\Core\Field\FieldDefinitionInterface[] An array of base field definitions for the entity type, keyed by field name.
See also
\Drupal\Core\Entity\FieldableEntityInterface::baseFieldDefinitions()
3 calls to RevisionLogEntityTrait::revisionLogBaseFieldDefinitions()
- EditorialContentEntityBase::baseFieldDefinitions in core/
lib/ Drupal/ Core/ Entity/ EditorialContentEntityBase.php - EntityTestMulRevChangedWithRevisionLog::baseFieldDefinitions in core/
modules/ system/ tests/ modules/ entity_test/ src/ Entity/ EntityTestMulRevChangedWithRevisionLog.php - RevisionableContentEntityBase::baseFieldDefinitions in core/
lib/ Drupal/ Core/ Entity/ RevisionableContentEntityBase.php
File
-
core/
lib/ Drupal/ Core/ Entity/ RevisionLogEntityTrait.php, line 28
Class
- RevisionLogEntityTrait
- Provides a trait for accessing revision logging and ownership information.
Namespace
Drupal\Core\EntityCode
public static function revisionLogBaseFieldDefinitions(EntityTypeInterface $entity_type) {
if (!$entity_type instanceof ContentEntityTypeInterface) {
throw new UnsupportedEntityTypeDefinitionException('The entity type ' . $entity_type->id() . ' is not a content entity type.');
}
foreach ([
'revision_created',
'revision_user',
'revision_log_message',
] as $revision_metadata_key) {
if (!$entity_type->hasRevisionMetadataKey($revision_metadata_key)) {
throw new UnsupportedEntityTypeDefinitionException('The entity type ' . $entity_type->id() . ' does not have an "' . $revision_metadata_key . '" entity revision metadata key.');
}
}
$fields[$entity_type->getRevisionMetadataKey('revision_created')] = BaseFieldDefinition::create('created')->setLabel(t('Revision create time'))
->setDescription(t('The time that the current revision was created.'))
->setRevisionable(TRUE);
$fields[$entity_type->getRevisionMetadataKey('revision_user')] = BaseFieldDefinition::create('entity_reference')->setLabel(t('Revision user'))
->setDescription(t('The user ID of the author of the current revision.'))
->setSetting('target_type', 'user')
->setRevisionable(TRUE);
$fields[$entity_type->getRevisionMetadataKey('revision_log_message')] = BaseFieldDefinition::create('string_long')->setLabel(t('Revision log message'))
->setDescription(t('Briefly describe the changes you have made.'))
->setRevisionable(TRUE)
->setDefaultValue('')
->setDisplayOptions('form', [
'type' => 'string_textarea',
'weight' => 25,
'settings' => [
'rows' => 4,
],
]);
return $fields;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.