Problem/Motivation
The AI Content Suggestions module currently looks for text fields in the node form. There are instances where it would be valuable to extract text fields from referenced items in the form. For example, an associated Media item with an extracted text field of the uploaded document could be used to suggest content. Another example would be the description fields on referenced taxonomy terms.
There's already similar handling for Paragraph entities:
// If we already have a paragraph of the correct type, just
// reuse it.
$paragraph = ($paragraph && $paragraph->bundle() == $bundle) ? $paragraph : $this->entityTypeManager->getStorage('paragraph')
->create([
'type' => $bundle,
]);
foreach ($this->getAllTextFields($paragraph, $form[$name]['widget'][$key]['subform']) as $machine => $label) {
$identifier = implode(':', [$name, $key, 'subform', $machine]);
$options[$identifier] = $field->getLabel() . ' (' . $key . ') > ' . $label;
}
Steps to reproduce
Proposed resolution
Attempt to load referenced entities and add any data from the fields on that entity that are text fields.
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork ai-3527520
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
jhedstromI added some proof-of-concept code that works. Some refinement would be needed to get this fully working across all entity types, etc.
Comment #5
anjaliprasannan commentedComment #6
anjaliprasannan commentedComment #7
valthebaldI see some common approach with how AI translate module extracts textual data from (sometimes nested) entity fields - there is FieldTextExtractorInterface introduced in https://www.drupal.org/node/3464024 and TextExtractor service that has extractTextMetadata/insertTextMetadata methods.
Can this be reused in content suggestions?
That would require some (minor) changes like moving the service and field plugins from ai_translate to ai module itself, but benefit IMO is bigger
Comment #8
valthebaldAlso, bumping target version
Comment #10
marcus_johansson commentedI set this to Needs work because of breaking changes.
@valthebald - moving such a service to the core might make sense, Automators might need it as well. We should check and possibly plan for it, when you have time.
Comment #11
valthebald@marcus created #3536887: Move TextExtractor service to AI core and assigned to myself. Will try to submit a proposal by Monday EOD
Comment #12
marcus_johansson commented