Problem/Motivation

Getting errors when viewing Recent Log Messages.

TypeError: Cannot access offset of type string on string in Drupal\views\Plugin\views\area\Text->preQuery() (line 51 of core/modules/views/src/Plugin/views/area/Text.php).

And one when deleting the messages
TypeError: Cannot access offset of type string on string in Drupal\views\Plugin\views\area\Text->render() (line 67 of core/modules/views/src/Plugin/views/area/Text.php).

Steps to reproduce

????

Issue fork drupal-3398734

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

Alen Simonyan created an issue. See original summary.

alen simonyan’s picture

Issue summary: View changes
alen simonyan’s picture

Here is the patch for this.

lendude’s picture

Status: Active » Postponed (maintainer needs more info)
Issue tags: +Needs steps to reproduce

Thanks for reporting this.

Do you have some steps to reproduce this on a clean Drupal install? Usually this is a symptom of a problem further up and just adding some checks is just hiding the real problem

alen simonyan’s picture

Hi @Lendude,

I diddn't manage to reproduce this on fresh install yet.

seutje’s picture

StatusFileSize
new1.56 KB

I also ran into this issue. The MR linked above fixed it for 9.x, but failed to apply when I upgraded to 10.x, so I rerolled it, but I changed it to fall back on $this->options['content']

Unfortunately, I have no clue what the cause is, so I cannot provide any more information... I have a strong suspicion it's being caused by a control module, as I only experience this issue with 1 specific project.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

lance lancelot’s picture

I encountered the same error and implemented a temporary fix, which needs review. The issue arises because $this->options['content'] is expected to be an array but can sometimes be a string.

Here’s the patch I applied to web/core/modules/views/src/Plugin/views/area/Text.php:

  /**
   * {@inheritdoc}
   */
  public function preQuery() {
    // Normalize $this->options['content'] to ensure it's an array.
    if (is_string($this->options['content'])) {
      // If it's a string, treat it as the content value with a default format.
      $this->options['content'] = [
        'value' => $this->options['content'],
        'format' => filter_default_format(),
      ];
    }

    // Proceed as normal with the now-normalized content array.
    $content = $this->options['content']['value'];

    // Check for tokens that require a total row count.
    if (str_contains($content, '[view:page-count]') || str_contains($content, '[view:total-rows]')) {
      $this->view->get_total_rows = TRUE;
    }
  }
lendude’s picture

Issue summary: View changes

$this->options['content'] is expected to be an array but can sometimes be a string

@lance lancelot Have you been able to pin down when or why this would be the case? We still need steps to reproduce this on a fresh Drupal install since as it stands currently, the error might just be the correct way to handle this because there is something wrong upstream.

lance lancelot’s picture

The error occurred after upgrading from Drupal 9 to Drupal 10. To investigate, I exported the configuration files and searched for occurrences of 'content:' strings.

For example, could the following configuration in views.view.comments_recent.yml be causing the error?

label: 'Recent comments'
description: 'Recent comments.'
display:
  default:
    display_title: Default
    display_options:
      title: 'Recent comments'
      fields:
        changed:
          settings:
            future_format: '@interval hence'
            past_format: '@interval ago'
      empty:
        area_text_custom:
         content: 'No comments available.' # Could this be the source of the problem?
  block_1:
    display_title: Block
    display_options:
      block_description: 'Recent comments'
      block_category: 'Lists (Views)'

I’m not entirely sure, but could the content: 'No comments available.' string format be causing the issue? Should it now be structured as:

content:
  value: 'No comments available.'
  format: 'plain_text'

Is this new format required in Drupal 10, and if so, was this change documented? I’d appreciate any clarification or guidance regarding this.

alxn’s picture

I just encountered this issue with Drupal 10.3.10 and Workbench 1.6

smustgrave’s picture

Before closing out anyone able to add concrete steps?

marieascomedia’s picture

Got the same problem on a watchdog view in a drupal 10 upgraded from 9.
After exporting configuration from that view and compared with one coming from a new drupal 10, I found this difference :

      empty:
        area:
          id: area
          table: views
          field: area
          relationship: none
          group_type: group
          admin_label: "Aucune entrée du journal n'est disponible."
          plugin_id: text
          empty: true
          content: "Aucune entrée du journal n'est disponible."
          tokenize: false

from the old

      empty:
        area:
          id: area_text_custom
          table: views
          field: area_text_custom
          relationship: none
          group_type: group
          admin_label: "Aucune entrée du journal n'est disponible."
          plugin_id: text_custom
          empty: true
          content: "Aucune entrée du journal n'est disponible."
          tokenize: false

from the new.

Re-importing the view config with only this difference make it works.

4kant’s picture

I had this issue last time I updated core from 9 to 10.3 and so far solved it via #7.
Today it popped up again when updating to 10.5.6.
After reading comments from #11 and #14 I looked into the configuration of the watchdog-view (/admin/structure/views/view/watchdog).
In the "No results behavior" area it said "Array (Array)".

All I had to do is replace that entry with a new text area containing the desired text.
So no patch necessary anymore.

Don´t know whether I found the cause of error for everyone. But maybe it helps to find it.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.