function image_field_config_delete

Same name in other branches
  1. 8.9.x core/modules/image/image.module \image_field_config_delete()
  2. 10 core/modules/image/image.module \image_field_config_delete()
  3. 11.x core/modules/image/image.module \image_field_config_delete()

Implements hook_ENTITY_TYPE_delete() for 'field_config'.

File

core/modules/image/image.module, line 479

Code

function image_field_config_delete(FieldConfigInterface $field) {
    $field_storage = $field->getFieldStorageDefinition();
    if ($field_storage->getType() != 'image') {
        // Only act on image fields.
        return;
    }
    // The value of a managed_file element can be an array if #extended == TRUE.
    $uuid = $field->getSetting('default_image')['uuid'];
    // Remove the default image when the instance is deleted.
    if ($uuid && ($file = \Drupal::service('entity.repository')->loadEntityByUuid('file', $uuid))) {
        \Drupal::service('file.usage')->delete($file, 'image', 'default_image', $field->uuid());
    }
}

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