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

Created on 12 January 2023, over 1 year ago
Updated 12 September 2023, 10 months 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

RTBC

Version

9.0

Component

Code

Created by

🇧🇪Belgium økse

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

Comments & Activities

Not all content is available!

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

  • First commit to issue fork.
  • 🇧🇪Belgium Mschudders

    Created the branch + applied the patch from: økse to that branch.

    Credits to økse

  • @mschudders opened merge request.
  • 🇧🇪Belgium økse

    The patch is a first proposition to come to a solution but isn't perfect by any means hence why I didn't upload it so far.

    Remaining room for improvement:

    • All the fields on the index (also the content type based added fields) are available to get the attachments indexed from. This should be improved to only allow non content type relevant fields
    • Changing the machine name of the search api attachments source field on the index does cause issues. This should definitly be improved to have a more flexible behaviour.
  • 🇧🇪Belgium økse

    I made an update to only allow non content type relevant fields (layout builder specific) to be indexed instead of all the fields coming from the index.

    Because of this, you don't longer need to use the Layout Builder Search API → contrib module (sorry maintainer) in order to get the reference as a field onto the search index. The update makes sure that referenced fields that have a reference to a file/media entity within block types in layout builder are available as indexable fields to get possible attachments indexed from.

    After fixing this, the machine name naming convention is no longer an issue.

  • Status changed to Needs review about 1 year ago
  • 🇧🇪Belgium tim-diels Belgium 🇧🇪

    When you provide an (updated) patch, you should set the issue to Needs Review to make it clear people can test this.

  • 🇧🇪Belgium tim-diels Belgium 🇧🇪

    Removed not needed use statements.

  • 🇧🇪Belgium tim-diels Belgium 🇧🇪

    Fixed the PHP CS issues form this issue.

  • Status changed to RTBC about 1 year ago
  • 🇧🇪Belgium tim-diels Belgium 🇧🇪

    Tested and works as expected. Thanks for the work done.

  • 🇧🇪Belgium kriboogh

    Tested, works.
    MR diff patch added for use in composer.

Production build 0.69.0 2024