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> 'target_id' => 123,<br> 'entity' => [...],<br> </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> return [<br> 'target_id' => $field_item->target_id,<br> 'entity' => $field_item->entity ? [<br> 'id' => $field_item->entity->id(),<br> 'label' => $field_item->entity->label(),<br> 'type' => $field_item->entity->getEntityTypeId(),<br> ] : NULL,<br> ];<br>}</pre><p>
Proposed code:</p>
<pre>// For entity reference fields, get target_id and other properties.<br>if (isset($properties['target_id'])) {<br> $result = [<br> 'target_id' => $field_item->target_id,<br> 'entity' => $field_item->entity ? [<br> 'id' => $field_item->entity->id(),<br> 'label' => $field_item->entity->label(),<br> 'type' => $field_item->entity->getEntityTypeId(),<br> ] : NULL,<br> ];<br> <br> // Add additional properties like alt, title, width, height for image fields.<br> foreach ($properties as $property_name => $property) {<br> if (!$property->getDataDefinition()->isComputed() && $property_name !== 'target_id') {<br> $value = $property->getValue();<br> if ($value !== NULL && $value !== '') {<br> $result[$property_name] = $value;<br> }<br> }<br> }<br> <br> 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