Argument #1 ($var) must be of type string

Created on 7 November 2023, about 1 year ago
Updated 8 November 2023, about 1 year ago

Using latest dev with with Drupal 10.1.6 if I add a token to the ouptu then I get this error message.

The token field in question is an image field, I haven't tested other field types.

TypeError: Drupal\views_conditional\Plugin\views\field\ViewsConditionalField::cleanVar(): Argument #1 ($var) must be of type string, Drupal\views\Plugin\views\field\EntityField given, called in /app/web/modules/contrib/views_conditional/src/Plugin/views/field/ViewsConditionalField.php on line 302 in Drupal\views_conditional\Plugin\views\field\ViewsConditionalField->cleanVar() (line 245 of modules/contrib/views_conditional/src/Plugin/views/field/ViewsConditionalField.php).

I saw a similar issue in the queue but it says that has been resolved so logging this too.

Cheers Dan

πŸ“Œ Task
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom danharper

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @danharper
  • πŸ‡ΊπŸ‡ΈUnited States grasmash

    Same issue here.

  • πŸ‡ΊπŸ‡ΈUnited States shelane

    The code that calls the cleanvar method:

        foreach ($labels as $key => $var) {
          // If we find a replacement variable, replace it.
          if (strpos($equalto, "{{ $key }}") !== FALSE) {
            $field = $this->cleanVar($fields[$key]);
            $equalto = str_replace("{{ $key }}", $field, $equalto);
          }
          if (strpos($then, "{{ $key }}") !== FALSE) {
            $field = $this->cleanVar($fields[$key]);
            $then = str_replace("{{ $key }}", $field, $then);
          }
          if (strpos($or, "{{ $key }}") !== FALSE) {
            $field = $this->cleanVar($fields[$key]);
            $or = str_replace("{{ $key }}", $field, $or);
          }
        }

    It looks like it's dealing with strings. What recommendation do you have for providing an "inclusive" type?

    I'll be out the next couple of hours, but I can look at this more when I get back.

  • πŸ‡ΊπŸ‡ΈUnited States grasmash

    Issue is that cleanVar() is set to accept only strings. But in the function body, it clearly expects to receive an object as it immediately checks for a ->last_render property.

  • Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    Waiting for branch to pass
  • @grasmash opened merge request.
  • Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    Waiting for branch to pass
  • Status changed to Fixed about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States shelane

    I appreciate the extra eye. I've got a bit much on my plate right now. I'll tag the updated release as soon as I get back.

  • πŸ‡ΊπŸ‡ΈUnited States grasmash

    No problem. Thanks for maintaining this module.

  • πŸ‡¬πŸ‡§United Kingdom danharper

    Just tried the latest dev but that hasn't worked, I'll try and have a look at the code later to see if I can patch.

    Should cleanVar only be used if I actually tick strip tags?

    The function is stripping the markup.

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

Production build 0.71.5 2024