Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Yes, it's an edge case but it need to be fixed too and, probably, will have to go in 9.0.x because changing the derivative URI can break existing sites that rely on specific URLs.
In the case illustrated by the test scenario, two different source images can generate the same derivative URI.
TL;DR:
$an_image = 'core/modules/example/image/picture.png';
$a_totally_different_image = 'public://core/modules/example/image/picture.png';
$first_image_uri = $style->buildUri($an_image);
$second_image_uri = $style->buildUri($a_totally_different_image);
// Check that different images are creating different derivative URIs.
self::assertNotEquals($first_image_uri, $second_image_uri);
This fails.
Proposed resolution
Come with a solution.
Remaining tasks
None.
User interface changes
None.
API changes
None.
Data model changes
The source images passed without a stream wrapper will have a different derivative URI.
Comment | File | Size | Author |
---|---|---|---|
#16 | interdiff_15-16.txt | 941 bytes | pooja saraah |
#16 | 2774449-16.patch | 2.58 KB | pooja saraah |
#15 | reroll_diff_edge_case_derivative_uri_collision-test-only-15.txt | 3.03 KB | pooja saraah |
#15 | 2774449-15.patch | 2.59 KB | pooja saraah |
edge_case_derivative_uri_collision-test-only.patch | 2.2 KB | claudiu.cristea | |
Comments
Comment #2
mondrakeIndeed.
Most visible example is the image style preview. In
image.settings.yml
we havepreview_image: core/modules/image/sample.png
With this,
template_preprocess_image_style_preview()
builds the preview image URI aspublic://styles/{image_style_id}/public/core/modules/image/sample.png
IMHO, this is a spot where #1308152: Add stream wrappers to access extension files would come in handy: changing
preview_image
topreview_image: 'module://image/sample.png'
would lead to a much nicer derivative URI
public://styles/{image_style_id}/module/image/sample.png
...In the end, do we really need to support building derivatives from a local file path, after all the efforts to use stream wrappers? Maybe in D9 we could only accept source URIs that have a scheme. This would allow for proper namespacing of the derivatives.
Comment #13
larowlanIs this still an issue?
Comment #15
pooja saraah CreditAttribution: pooja saraah at Material for Drupal India Association commentedaddressed #2 and attached the patch against 9.4.x
Comment #16
pooja saraah CreditAttribution: pooja saraah at Material for Drupal India Association commentedFixed failed Commands #15 and attached patch