Cannot unload entity reference field in content entity base table

Created on 25 February 2023, almost 2 years ago
Updated 26 February 2023, almost 2 years ago

Problem/Motivation

Use hook_ entity_ base_ field_ Info () adds entity reference fields for user entities, which cannot be uninstalled after cancellation.

Steps to reproduce

1、Add Entity Reference Field:

function test_entity_base_field_info(EntityTypeInterface $entity_type) {
$fields = [];

if ($entity_type->id() === 'user') {
$fields['test'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Authored by'))
->setDescription(t('The user ID of author of the Apps content entity.'))
->setRevisionable(TRUE)
->setSetting('target_type', 'user')
->setSetting('handler', 'default')
->setTranslatable(TRUE)
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'author',
'weight' => 0,
])
->setDisplayOptions('form', [
'type' => 'entity_reference_autocomplete',
'weight' => 5,
'settings' => [
'match_operator' => 'CONTAINS',
'size' => '60',
'autocomplete_type' => 'tags',
'placeholder' => '',
],
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
}

return $fields;
}

2、Delete the field hook added in the previous step, and unload the entity entity reference field

3、Error message:

The form display and display are deleted normally, but the entity reference field in the users_field_data table fails to be deleted

\Drupal::entityDefinitionUpdateManager()->uninstallFieldStorageDefinition($field_storage_definition),Same question.

🐛 Bug report
Status

Active

Version

10.1

Component
Entity 

Last updated about 9 hours ago

Created by

🇨🇳China qiutuo

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @qiutuo
  • What does “and unload the entity entity reference field” in step two mean, technically?

  • 🇨🇳China qiutuo

    When you remove the hook in step 1, the newly added entity reference field in the user entity should be removed synchronously, but this is not possible now,

    After testing, the fields in the core, only the entity reference fields cannot be deleted,

Production build 0.71.5 2024