Problem/Motivation

Trying to add a field to a view based on meilisearch index does nothing and a PHP error is returned/logged on Drupal 11 instance.

The logs show the following error.

TypeError: Drupal\Component\Utility\Html::escape(): Argument #1 ($text) must be of type string, null given, called in /var/www/html/web/core/lib/Drupal/Component/Render/FormattableMarkup.php on line 238 in Drupal\Component\Utility\Html::escape() (line 431 of /var/www/html/web/core/lib/Drupal/Component/Utility/Html.php).

Steps to reproduce

  1. Create a new view based on meilisearch index (View settings: Index {INDEX_NAME}) or edit existing view
  2. In the Fields section click Add button
  3. Nothing happens, the ajax request returns 500 response and an error message is displayed on top
  4. The logs show the php error described above

Proposed resolution

On investigating the issue, the problem lies in how the module handles special search api fields. In #3396022: Error when indexing special fields (search_api_*) we clone special fields as backend defined fields, however this is incorrect as special fields are not meant to be visible and/or added through UI.

Since the special fields do not hold any labels the cloned backend defined fields also contain no label and the error is thrown.

A quick fix would be to use empty string where NULL labels are returned however the underlying issue should be fixed and special fields should be handled properly.

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

bcizej created an issue. See original summary.

bcizej’s picture

Status: Active » Needs review

PR created

Anonymous’s picture

Status: Needs review » Reviewed & tested by the community

I've checked this branch locally with clean install of D11 and tested this by creating a new view and then applying sorting on the indexed attributes. I've also reviewed code in the MR and everything seems to be ok. Marking this as RTBC.

  • bcizej committed a9cb83bb on 2.x
    Issue #3530985 by bcizej, jernejmramor: PHP error in views when adding...
bcizej’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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