Skip to content

Commit

Permalink
Use fastly api service to purge file URL when file is deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
neilblair committed Feb 7, 2022
1 parent da587b4 commit 3fe9c02
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions origins_media/origins_media.module
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,20 @@ function origins_media_form_alter(&$form, FormStateInterface $form_state, $form_
}
}

/**
* Implements hook_ENTITY_TYPE_delete().
*/
function origins_media_file_delete(EntityInterface $entity) {
// Purge file URL from Fastly.
$url = $entity->createFileUrl($relative = FALSE);
if (!empty(\Drupal::hasService('fastly.api'))) {
$fastly = Drupal::service('fastly.api');
if (!empty($url)) {
$fastly->purgeUrl($url);
}
}
}

/**
* Implements hook_preprocess_views_view_field().
*
Expand Down

0 comments on commit 3fe9c02

Please sign in to comment.