Make it possible to index attachments from index only fields that don't exist on the entity

Created on 12 January 2023, about 2 years ago
Updated 13 February 2023, about 2 years ago

Problem/Motivation

When adding fields on the index (through for instance the use of a Search API processor) that don't exist on the entity, these fields don't get picked up the Search API processor from this module to be able to index the containing attachments.

Steps to reproduce

Example that happens with layout builder in combination with a document block (media reference). By default only the title and filename are available through a rendered item. If you would like to get the actual attachment indexed, you need to get the reference as a field onto the search index. This can be done through the use of the Layout Builder Search API β†’ contrib.

Hereafter, the fields are available on the search index (media reference) but don't actually get picked up by the Search API processor from Search API Attachments.

Proposed resolution

Make sure that fields with a media/file reference that don't exist on the entity get picked up by adapting the getFileFieldsAndFileEntityItems function.

foreach ($this->getIndex()->getDatasources() as $datasource) {
            // Current code.
            }

            // @todo Suggested implementation for indexed fields that don't exist on the entity.

After the field is available to get the attachments indexed from, adapt the addFieldValues function to actually provide this.

foreach ($this->fieldHelper->filterForPropertyPath($item->getFields(), NULL, $property_path) as $field) {
          $all_fids = [];
          if ($entity->hasField($field_name)) {
          // Current code.
          } else {
          // @todo Suggested implementation for indexed fields that don't exist on the entity.
          }

Remaining tasks

Write a patch implementing the feature request and get this reviewed by the community.

✨ Feature request
Status

Active

Version

9.0

Component

Code

Created by

πŸ‡§πŸ‡ͺBelgium ΓΈkse

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024