Code to reproduce:
{code}
$style = \Drupal\image\Entity\ImageStyle::load('thumbnail');
$style->flush('http://www.example.com/');
{code}
Error: GuzzleHttp\Exception\ConnectException: cURL error 6: Couldn't resolve host 'styles' (see http://curl.haxx.se/libcurl/c/libcurl-errors.html) in GuzzleHttp\Handler\CurlFactory::createRejection() (line 186 of vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php).
This is because ImageStyle::flush() just calls $this->buildUri(), which generates a result of http://styles/www.example.com
which we don't get a chance to correct like we do when image derivatives are output, which calls file_create_url() and our alter hook gets the chance to execute.
Comment | File | Size | Author |
---|---|---|---|
#5 | 2785939-cleanup-image-style-handling.patch | 13.74 KB | Dave Reid |
#3 | 2785939-cleanup-image-style-handling.patch | 11.74 KB | Dave Reid |
Comments
Comment #2
Dave ReidUgghhhh, we were at least able to handle this in D7 because image_style_flush() did not return early and allowed hook_image_style_flush() to execute. Execution simply stops in ImageStyle::flush() when the file_exists fails.
We really really could use #1358896: Flexible scheme and URI for image derivatives.
Comment #3
Dave ReidFuck it, let's just override the ImageStyle class. This simplifies a lot of code.
Comment #4
deviantintegral CreditAttribution: deviantintegral at Lullabot commentedLooking good!
Should we be using https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21... ?
Either way, the docblock doesn't match the hook.
Is there an issue to make this procedural code OOP / testable?
Comment #5
Dave ReidIt looks like hook_entity_type_alter is what I should use to alter existing things rather than adding new things. Also, THANKS FILE ENTITY (where I got the example from).
#2778103: Convert file_is_* helper functions to a service class. For now I've copied what the original ImageStyle class does for unit testability and added a wrapper method.
Comment #7
Dave ReidMerged #5 to 8.x-1.x. Thanks!