Score:0

How to completly remove a field?

sa flag

I have removed a field from a bundle (it is not used somewhere else) by using the graphical UI.

But it is still listed when I run the following command (after cache clear)

$this->entityFieldManager->getFieldDefinitions('node', $bundle); 

What should I do to completely remove it (as I use the previous command to display some list)

edit to add:

Following the proposal of Clive, I ran the field_cron() without success. Looking at the code of this function, I tried the following code to have more information:

$deleted_fields_repository = \Drupal::service('entity_field.deleted_fields_repository');
$fields = $deleted_fields_repository->getFieldDefinitions(NULL);

As you can imagine, $fields is empty. Maybe some kind of corruption?

edit to add 2

Following the proposal of 4k4 I ran this code:

$field_storage = \Drupal\field\Entity\FieldStorageConfig::loadByName('node', 'the_field_that_must_be_deleted');
dpm($field_storage->get('persist_with_no_fields'));

And the result is FALSE

Thus the question is: how to manually remove a field?

4uk4 avatar
cn flag
Could be the field storage is marked as persist_with_no_fields, which means it should persist even if no longer used in any bundle.
Baud avatar
sa flag
@4k4: I have updated my question: looks like it is not the case
Score:0
cn flag

Usually you would just run cron for this, because field_cron() clears the deleted data.

If you need to do it manually for whatever reason, you can call field_purge_batch() manually.

Baud avatar
sa flag
Thank you. Looks like it is a correct answer but not useful in my case. I have updated my question.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.