You are here

function _entity_usage_field_deleted_helper in Entity Usage 8.3

2 calls to _entity_usage_field_deleted_helper()
entity_usage_field_config_delete in ./entity_usage.module
Implements hook_ENTITY_TYPE_delete() for field_config.
entity_usage_field_storage_config_delete in ./entity_usage.module
Implements hook_ENTITY_TYPE_delete() for field_storage_config.

File

./entity_usage.module, line 97
Contains entity_usage.module.

Code

function _entity_usage_field_deleted_helper(EntityInterface $field) {
  if ($field instanceof FieldConfigInterface || $field instanceof FieldStorageConfigInterface) {

    // When deleting a field on a top or middle-level entity, this might
    // generate stale data. Set the regeneration flag in that scenario.
    // @todo Consider: 1) Being less aggressive on reaching this conclusion, and
    // 2) in case a regeneration is indeed needed, maybe we should trigger a
    // queue to actually start regenerating, instead of just setting the flag?
    $entity_type = $field
      ->getTargetEntityTypeId();
    $top_level_types = EntityUsageSourceLevel::getTopLevelEntityTypes();
    $middle_level_types = EntityUsageSourceLevel::getMiddleLevelEntityTypes();
    if (in_array($entity_type, $top_level_types) || in_array($entity_type, $middle_level_types)) {
      \Drupal::state()
        ->set('entity_usage_needs_regeneration', TRUE);
    }
  }
}