I've created a new custom basefield for user
entity type like this:
function hd_is_integration_entity_base_field_info_alter(&$fields, \Drupal\Core\Entity\EntityTypeInterface $entity_type) {
if ($entity_type->id() === 'user') {
$fields['is_uid'] = BaseFieldDefinition::create('text')
->setName('is_uid')
->setLabel(t('IS User ID'))
->setDescription(t('ID of this user in HD IS.'))
->setSettings([
'max_length' => 50,
'text_processing' => 0,
])
->setDefaultValue('')
->setDisplayOptions('view', [
'label' => 'above',
'type' => 'string',
'weight' => 0,
])
->setDisplayOptions('form', [
'type' => 'string_textfield',
'weight' => 0,
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
}
}
I've also updated the entity schema with update hook:
function hd_is_integration_update_8001(&$sandbox) {
$field_storage_definition = BaseFieldDefinition::create('string')
->setName('is_uid')
->setLabel(t('IS User ID'))
->setDescription(t('ID of this user in HD IS.'))
->setSettings([
'max_length' => 50,
'text_processing' => 0,
])
->setDefaultValue('')
->setDisplayOptions('view', [
'label' => 'above',
'type' => 'string',
'weight' => 0,
])
->setDisplayOptions('form', [
'type' => 'string_textfield',
'weight' => 0,
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
\Drupal::entityDefinitionUpdateManager()
->installFieldStorageDefinition('is_uid', 'user', 'user', $field_storage_definition);
}
The field is displaying fine in the user edit form, but any value added in it isn't saved. What am I missing, please?