public static function EntityLegalDocumentAcceptance::baseFieldDefinitions in Entity Legal 3.0.x
Same name and namespace in other branches
- 8.2 src/Entity/EntityLegalDocumentAcceptance.php \Drupal\entity_legal\Entity\EntityLegalDocumentAcceptance::baseFieldDefinitions()
- 4.0.x src/Entity/EntityLegalDocumentAcceptance.php \Drupal\entity_legal\Entity\EntityLegalDocumentAcceptance::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/ EntityLegalDocumentAcceptance.php, line 33
Class
- EntityLegalDocumentAcceptance
- Defines the entity legal document acceptance entity.
Namespace
Drupal\entity_legal\EntityCode
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields['aid'] = BaseFieldDefinition::create('integer')
->setLabel(t('Entity ID'))
->setDescription(t('The entity ID of this agreement.'))
->setReadOnly(TRUE)
->setSetting('unsigned', TRUE);
$fields['document_version_name'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Document version'))
->setDescription(t('The name of the document version this acceptance is bound to.'))
->setSetting('target_type', ENTITY_LEGAL_DOCUMENT_VERSION_ENTITY_NAME)
->setRequired(TRUE);
$fields['uid'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Author'))
->setDescription(t('The author of the acceptance.'))
->setSetting('target_type', 'user')
->setDefaultValueCallback('Drupal\\entity_legal\\Entity\\EntityLegalDocumentAcceptance::getCurrentUserId')
->setRequired(TRUE);
$fields['acceptance_date'] = BaseFieldDefinition::create('created')
->setLabel(t('Date accepted'))
->setDescription(t('The date the document was accepted.'));
$fields['data'] = BaseFieldDefinition::create('string_long')
->setLabel(t('Data'))
->setDescription('A dump of user data to help verify acceptances.')
->setDefaultValueCallback('Drupal\\entity_legal\\Entity\\EntityLegalDocumentAcceptance::getData');
return $fields;
}