Align and caption filter haystack errors due to php 8.1

Created on 4 March 2023, about 2 years ago
Updated 8 March 2023, about 2 years ago

Problem/Motivation

On upgrade the https://www.drupal.org/project/poll module stopped working - when submitting a vote the following errors were seen along with a third (similar) one from the linkit filter:

TypeError: stristr(): Argument #1 ($haystack) must be of type string, array given in stristr() (line 69 of /mysite/html/core/modules/filter/src/Plugin/Filter/FilterCaption.php) 

TypeError: stristr(): Argument #1 ($haystack) must be of type string, array given in stristr() (line 27 of /mysite/html/core/modules/filter/src/Plugin/Filter/FilterAlign.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 first 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

Release notes snippet

🐛 Bug report
Status

Closed: works as designed

Version

9.5

Component
Filter 

Last updated about 2 hours ago

No maintainer
Created by

🇨🇦Canada joel_osc

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

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 about 2 years 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 %}

    Cheers!

Production build 0.71.5 2024