Linkit filter haystack error due to php 8.1

Created on 4 March 2023, over 1 year ago
Updated 8 March 2023, over 1 year ago

Problem/Motivation

On upgrade the https://www.drupal.org/project/poll β†’ module stopped working - when submitting a vote the following error was seen along with a 2 (similar) errors from core filter (align and caption):

TypeError: strpos(): Argument #1 ($haystack) must be of type string, array given in strpos() (line 83 of /mysite/html/modules/contrib/linkit/src/Plugin/Filter/LinkitFilter.php)

PHP version: 8.1.16

Steps to reproduce

1. Install the poll module
2. Add the poll block to the home page
3. Create a poll
4. Submit a poll vote and the ajax submission will fail and the filter error will appear in the logs

Proposed resolution

Check for empty text before processing.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Closed: works as designed

Version

5.0

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada joel_osc

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.

  • Issue created by @joel_osc
  • πŸ‡¨πŸ‡¦Canada joel_osc

    Here is a patch that fixes the issue.

  • Status changed to Closed: works as designed over 1 year ago
  • πŸ‡¨πŸ‡¦Canada joel_osc

    Withdrawing this issue, code is working as designed. In case anyone else sees this error in php8.1 you may want to look at your twig and add a check to see if the field value is empty before rendering a "Text (formatted, long)" field in this manner:

      {% if not node.field_my_textarea.value is empty %}
          {% set my_processed_text = {
            '#type':   'processed_text',
            '#text':    node.field_my_textarea.value,
            '#format': 'rich_text',
          } %}
          {{ my_processed_text }}
      {% endif %}
Production build 0.69.0 2024