Numeric metadata values (ISO, Aperture, Focal Length) not returned by getMetadata()
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3565155. --> Reported by: [ecvandenberg](https://www.drupal.org/user/819336) Related to !1 >>> <p>I had this issue and my Copilot came with this solution. And it looks good and works fine.<br> I will try to create an MR.<br> Hope this helps.</p> <p>## Problem/Motivation</p> <p>The `ImageWithMetadata::getMetadata()` method only returns string values due to an `is_string()` check on line 187. This causes numeric EXIF values like ISO speed, aperture, and focal length to be ignored, even though they are correctly extracted by `ImageMetadataHelper::normalizeMetadata()`.</p> <p>## Steps to reproduce</p> <p>1. Configure a media type to use metadata extraction<br> 2. Map fields to numeric metadata attributes (iso, aperture, focal_length)<br> 3. Upload an image with complete EXIF data<br> 4. Call `$source-&gt;getMetadata($media, 'iso')` - returns NULL<br> 5. Call `$source-&gt;getMetadata($media, 'camera_model')` - returns string correctly</p> <p>## Expected behavior</p> <p>All metadata attributes should be returned, regardless of whether they are strings or numeric values.</p> <p>## Actual behavior</p> <p>Only string metadata values are returned. Numeric values (ISO: 160, Aperture: 4.0, Focal Length: 70) return NULL.</p> <p>## Proposed resolution</p> <p>Update the condition in `ImageWithMetadata::getMetadata()` to handle both string and numeric values:</p> <pre>// Current code (line 187):<br>if (!empty($normalized_metadata[$name]) &amp;&amp; is_string($normalized_metadata[$name])) {<br>&nbsp; return html_entity_decode(Xss::filter($normalized_metadata[$name]), ENT_QUOTES | ENT_HTML5, 'UTF-8');<br>}<br><br>// Proposed fix:<br>if (!empty($normalized_metadata[$name]) || (isset($normalized_metadata[$name]) &amp;&amp; is_numeric($normalized_metadata[$name]))) {<br>&nbsp; $value = $normalized_metadata[$name];<br>&nbsp; // Only filter strings through Xss::filter<br>&nbsp; if (is_string($value)) {<br>&nbsp;&nbsp;&nbsp; return html_entity_decode(Xss::filter($value), ENT_QUOTES | ENT_HTML5, 'UTF-8');<br>&nbsp; }<br>&nbsp; // Return numeric values as strings<br>&nbsp; return (string) $value;<br>}</pre><p>This ensures:<br> - String values are sanitized through Xss::filter as before<br> - Numeric values are cast to strings and returned<br> - Zero values (ISO: 0) are properly handled</p> <p>## Affected methods</p> <p>- `Drupal\media_image_metadata\Plugin\media\Source\ImageWithMetadata::getMetadata()`</p> <p>## Version</p> <p>Tested on media_image_metadata 1.0.6</p>
issue