-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BUGS-5816: Resolves issue where changing file content would not serve…
… new files. Contributors: * [nsciacca](https://git.drupalcode.org/nsciacca) * [Ec1ipsis](https://git.drupalcode.org/Ec1ipsis)
- Loading branch information
Ryan Wagner
committed
Mar 15, 2024
1 parent
96d5b49
commit fa9e3bc
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
use Drupal\Core\Entity\EntityInterface; | ||
use Drupal\image\Entity\ImageStyle; | ||
|
||
/** | ||
* Implements hook_ENTITY_TYPE_update() for file entities. | ||
* | ||
* Clears edge cache by file url. If this is not done, changing file contents | ||
* does not actually change the file that gets served until the cache times out. | ||
*/ | ||
function pantheon_advanced_page_cache_file_update(EntityInterface $file) { | ||
// Don't try this if we're not in a Pantheon environment. | ||
if (function_exists('pantheon_clear_edge_paths')) { | ||
// No matter what, the file's base URL needs to be cleared out . | ||
$paths_to_clear = [$file->createFileUrl()]; | ||
|
||
// If this is an image, we need to clear the edge cache paths for every | ||
// image style, or those won't work. | ||
if (strpos($file->getMimeType(), 'image', 0) === 0) { | ||
$styles = ImageStyle::loadMultiple(); | ||
foreach ($styles as $style) { | ||
$file_uri = $file->getFileUri(); | ||
$url = $style->buildUrl($file_uri); | ||
|
||
$paths_to_clear[] = parse_url($url)['path']; | ||
} | ||
} | ||
|
||
pantheon_clear_edge_paths($paths_to_clear); | ||
} | ||
} |