Field API bulk data deletion

Same name and namespace in other branches
  1. 7.x modules/field/ \field_purge
  2. 9 core/modules/field/ \field_purge
  3. 8.9.x core/modules/field/ \field_purge
  4. 10 core/modules/field/ \field_purge

Cleans up after Field API bulk deletion operations.

Field API provides functions for deleting data attached to individual entities as well as deleting entire fields or field storages in a single operation.

When a single entity is deleted, the Entity storage performs the following operations:

  • Invoking the method \Drupal\Core\Field\FieldItemListInterface::delete() for each field on the entity. A file field type might use this method to delete uploaded files from the filesystem.
  • Removing the data from storage.
  • Invoking the global hook_entity_delete() for all modules that implement it. Each hook implementation receives the entity being deleted and can operate on whichever subset of the entity's bundle's fields it chooses to.

Similar operations are performed on deletion of a single entity revision.

When a bundle, field or field storage is deleted, it is not practical to perform those operations immediately on every affected entity in a single page request; there could be thousands or millions of them. Instead, the appropriate field data items, fields, and/or field storages are marked as deleted so that subsequent load or query operations will not return them. Later, a separate process cleans up, or "purges", the marked-as-deleted data by going through the three-step process described above and, finally, removing deleted field storage and field records.

Purging field data is made somewhat tricky by the fact that, while $entity->delete() has a complete entity to pass to the various deletion steps, the Field API purge process only has the field data it has previously stored. It cannot reconstruct complete original entities to pass to the deletion operations. It is even possible that the original entity to which some Field API data was attached has been itself deleted before the field purge operation takes place.

Field API resolves this problem by using stub entities during purge operations, containing only the information from the original entity that Field API knows about: entity type, ID, revision ID, and bundle. It also contains the field data for whichever field is currently being purged.

See Field API for information about the other parts of the Field API.


core/modules/field/, line 12


Title Sort descending File name Summary
field_purge_batch core/modules/field/ Purges a batch of deleted Field API data, field storages, or fields.
field_purge_field core/modules/field/ Purges a field record from the database.
field_purge_field_storage core/modules/field/ Purges a field record from the database.
hook_field_purge_field core/modules/field/field.api.php Acts when a field is being purged.
hook_field_purge_field_storage core/modules/field/field.api.php Acts when a field storage definition is being purged.
hook_field_type_category_info_alter core/modules/field/field.api.php Allows modules to alter the field type category information.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.