Problem/Motivation

If we use in our Drupal search custom datasources, those may have no view modes so in the line https://git.drupalcode.org/project/search_api/-/blob/8.x-1.38/src/Plugin... it will throw a TypeError: Cannot access offset of type string on string

Steps to reproduce

Use a custom datasource within a Search view.

Proposed resolution

Ensure that the datasource config is an array to prevent the type error.

Issue fork search_api-3542573

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

alae.akalay created an issue. See original summary.

drunken monkey made their first commit to this issue’s fork.

drunken monkey’s picture

Version: 8.x-1.38 » 8.x-1.x-dev
Component: General code » Views integration
Category: Support request » Bug report
Status: Active » Needs review

Thanks a lot for reporting this problem!
I can reproduce it: If a datasource does not support viewing items, the SearchApiRow plugin will crash the whole page request.

However, while your patch would avoid that fatal error, I think the proper solution is slightly more complex:

  1. We should amend the options form code for the plugin to not save that bogus option in the first place, since that also violates the config schema.
  2. In render(), we should explicitly check whether the datasource supports viewing items and bail early otherwise. With your suggested code, we would still call $datasource->viewItem() which would likely result in an exception or error itself.

I created an MR with those fixes, please review!

drunken monkey’s picture

Status: Needs review » Fixed

Merged.

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.

  • drunken monkey committed 22c946f1 on 8.x-1.x
    [#3542573] fix: Fixed the “Rendered entity” Views row style to properly...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.