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

Command icon 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

jhedstrom created an issue. See original summary.

jhedstrom’s picture

Status: Active » Needs review

I added some proof-of-concept code that works. Some refinement would be needed to get this fully working across all entity types, etc.

anjaliprasannan made their first commit to this issue’s fork.

anjaliprasannan’s picture

Assigned: Unassigned » anjaliprasannan
anjaliprasannan’s picture

Assigned: anjaliprasannan » Unassigned
valthebald’s picture

I 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

valthebald’s picture

Version: 1.1.x-dev » 1.2.x-dev
Component: Other Submodules » AI Content Suggestions

Also, bumping target version

marcus_johansson made their first commit to this issue’s fork.

marcus_johansson’s picture

Status: Needs review » Needs work

I 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.

valthebald’s picture

@marcus created #3536887: Move TextExtractor service to AI core and assigned to myself. Will try to submit a proposal by Monday EOD

marcus_johansson’s picture

Project: AI (Artificial Intelligence) » AI content
Version: 1.2.x-dev »
Component: AI Content Suggestions » Code