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');

And the result is FALSE

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

  • 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.
    – 4k4
    Jan 11 at 19:39
  • @4k4: I have updated my question: looks like it is not the case
    – Baud
    Jan 12 at 8:50

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.

  • Thank you. Looks like it is a correct answer but not useful in my case. I have updated my question.
    – Baud
    Jan 11 at 17:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.