Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
When referencing an image field type from a TWIG file, there is no way to retrieve the image's URI as is possible when referencing image fields when exposed from within other objects types such as nodes. The only values available are target_id, alt, title, width, and height. The entity object is not available.
Comment | File | Size | Author |
---|---|---|---|
#4 | image_field_reference-2863738-4.patch | 3.34 KB | scott_euser |
Comments
Comment #2
mgalgano CreditAttribution: mgalgano commentedComment #3
mgalgano CreditAttribution: mgalgano commentedI addressed the issue for my purposes specifically by updating SiteSettingsLoader.php. Please consider this, or a similar possibly more robust, modification in a future release.
private function getValues($entity) {
...
// Exclude fields on the object that are base config.
if (!method_exists(get_class($field_definition), 'isBaseField') || !$field_definition->isBaseField()) {
if ($field_definition->getType() == "image") {
$build[$key] = $field;
} else {
if ($value = $field->getValue()) {
...
}
...
}
Comment #4
scott_euser CreditAttribution: scott_euser as a volunteer and at Fat Beehive commentedWould the attached patch work for you? As the site settings are heavily cached in one chunk for performance, I would like to avoid storing the entire entity with it.
Comment #5
scott_euser CreditAttribution: scott_euser as a volunteer and at Fat Beehive commentedComment #6
scott_euser CreditAttribution: scott_euser as a volunteer and at Fat Beehive commentedThis has been added on the dev branch.