Skip to content

Support additional entity types in label resolution (taxonomy terms, media, etc.) #7

@jjroelofs

Description

@jjroelofs

Proposal

The current entity reference label resolution in extractItemValue() only resolves the label for the referenced entity. For better AI/analysis output, consider enhancing the entity reference data structure.

Current Implementation

File: src/Service/ContentIntelCollector.php
Lines: 360-371

if (in_array($type, ['entity_reference', 'entity_reference_revisions'])) {
  $entity = $item->entity;
  if ($entity) {
    return [
      'target_id' => $item->target_id,
      'target_type' => $entity->getEntityTypeId(),
      'label' => $entity->label(),
    ];
  }
  return ['target_id' => $item->target_id];
}

Proposed Enhancements

1. Add Bundle Information

For taxonomy terms, knowing the vocabulary is often more useful than just "taxonomy_term":

return [
  'target_id' => $item->target_id,
  'target_type' => $entity->getEntityTypeId(),
  'target_bundle' => $entity->bundle(),  // e.g., "tags", "categories"
  'label' => $entity->label(),
];

2. Add URL for Linkable Entities

if ($entity->hasLinkTemplate('canonical')) {
  $data['url'] = $entity->toUrl('canonical')->setAbsolute()->toString();
}

3. Handle Media Entities Specially

Media entities often benefit from including the source file URL:

if ($entity->getEntityTypeId() === 'media') {
  $source = $entity->getSource();
  $source_field = $source->getSourceFieldDefinition($entity->bundle);
  // Extract thumbnail or source file URL
}

Benefits

  • Richer Data: More context about referenced entities
  • AI-Friendly: Better understanding of relationships
  • Reduced Lookups: Consumers don't need to make additional API calls

Involved Components

  • src/Service/ContentIntelCollector.php - Enhance extractItemValue() method

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions