Undefined offset for raw field value when views arguments missing

Created on 10 March 2021, almost 4 years ago
Updated 30 May 2023, over 1 year ago

Problem/Motivation

Create a view that has a views_field_view plus two contextual filters.

Editing the view, when no arguments are supplied, results in the message:

Notice: Undefined offset: 1 in Drupal\views_field_view\Plugin\views\field\View->getTokenValue() (line 321 of /home/james/xequals/smartbuild/web/modules/contrib/views_field_view/src/Plugin/views/field/View.php)

The problem is that the code block in the plugin class View.php

      case 'raw_arguments':
        $value = $view->args[array_flip(array_keys($view->argument))[$id]];
        break;

is called to return the value to the second element in $view->args, but this does not exist.

Proposed resolution

Replace the switch code snippet with

      case 'raw_arguments':
        $value = NULL;
        $arg_id = array_flip(array_keys($view->argument))[$id];
        if (isset($view->args[$arg_id])) {
          $value = $view->args[$arg_id];
        }
        break;
πŸ› Bug report
Status

Needs review

Version

1.0

Component

Miscellaneous

Created by

πŸ‡³πŸ‡ΏNew Zealand jlscott

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.

  • πŸ‡ΊπŸ‡ΈUnited States beunerd Providence, Rhode Island

    The patch didn't seem to help (drupal 9.5.2, php 8.1), but as a workaround try adding a hidden custom text field to the view toward the top of the list of fields with twig to conditionally look for that key if it exists: {% if raw_arguments.term_node_tid_depth is defined %}{{ raw_arguments.term_node_tid_depth }}{% endif %}. Then you can just reference that hidden custom text field as the argument in your views_field_view (e.g., {{ fields.nothing }}

  • πŸ‡΅πŸ‡±Poland Patryk Padus

    I use this that work in today version:

          case 'raw_fields':
            $value = NULL;
            if (isset($view->field[$id])) {
              $value = $view->field[$id]->getValue($values);
            }
            break;
    
Production build 0.71.5 2024