EntityFieldValues tool doesn't return image field metadata (alt, title, width, height)
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3563382. --> Reported by: [prabha1997](https://www.drupal.org/user/3624779) Related to !65 >>> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p>The entity_field_values tool currently returns incomplete data for image fields and other entity reference fields that have additional metadata properties. When querying a media entity's field_media_image field, only the target_id and basic entity information are returned, while important metadata like alt, title, width, and height are excluded.</p> <p>The issue is in the getFieldItemValue() method in src/Plugin/tool/Tool/EntityFieldValues.php, which returns early when it encounters a target_id property without checking for other field properties.</p> <h4 id="summary-steps-reproduce">Steps to reproduce</h4> <ol> <li>Create or load a media entity (e.g., media:1) with an image that has alt text set</li> <li>Use the entity_field_values tool to retrieve field values</li> <li>Request the field_media_image field specifically</li> <li>Observe that the returned data only contains:</li> <li> <pre>&nbsp;&nbsp; 'target_id' =&gt; 123,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'entity' =&gt; [...],<br>&nbsp; </pre></li> <li>Notice that alt, title, width, and height properties are missing</li> </ol> <h3 id="summary-proposed-resolution">Proposed resolution</h3> <p>Modify the getFieldItemValue() method to include all non-computed properties for entity reference fields, not just target_id and entity information.</p> <p>Current Code:</p> <pre>// For entity reference fields, get target_id.<br>if (isset($properties['target_id'])) {<br>&nbsp; return [<br>&nbsp;&nbsp;&nbsp; 'target_id' =&gt; $field_item-&gt;target_id,<br>&nbsp;&nbsp;&nbsp; 'entity' =&gt; $field_item-&gt;entity ? [<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'id' =&gt; $field_item-&gt;entity-&gt;id(),<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'label' =&gt; $field_item-&gt;entity-&gt;label(),<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'type' =&gt; $field_item-&gt;entity-&gt;getEntityTypeId(),<br>&nbsp;&nbsp;&nbsp; ] : NULL,<br>&nbsp; ];<br>}</pre><p> Proposed code:</p> <pre>// For entity reference fields, get target_id and other properties.<br>if (isset($properties['target_id'])) {<br>&nbsp; $result = [<br>&nbsp;&nbsp;&nbsp; 'target_id' =&gt; $field_item-&gt;target_id,<br>&nbsp;&nbsp;&nbsp; 'entity' =&gt; $field_item-&gt;entity ? [<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'id' =&gt; $field_item-&gt;entity-&gt;id(),<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'label' =&gt; $field_item-&gt;entity-&gt;label(),<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'type' =&gt; $field_item-&gt;entity-&gt;getEntityTypeId(),<br>&nbsp;&nbsp;&nbsp; ] : NULL,<br>&nbsp; ];<br>&nbsp; <br>&nbsp; // Add additional properties like alt, title, width, height for image fields.<br>&nbsp; foreach ($properties as $property_name =&gt; $property) {<br>&nbsp;&nbsp;&nbsp; if (!$property-&gt;getDataDefinition()-&gt;isComputed() &amp;&amp; $property_name !== 'target_id') {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $value = $property-&gt;getValue();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ($value !== NULL &amp;&amp; $value !== '') {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $result[$property_name] = $value;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp; }<br>&nbsp; <br>&nbsp; return $result;<br>}</pre><h3 id="summary-remaining-tasks">Remaining tasks</h3> <h3 id="summary-ui-changes">User interface changes</h3> <p>None.</p> <h3 id="summary-api-changes">API changes</h3> <h3 id="summary-data-model-changes">Data model changes</h3> <p>None</p>
issue