Problem/Motivation

The user gets the following notices when the Flexible Views is used with Views Conditional:

* Notice: Undefined index: field_brandcare_status in Drupal\flexible_views\Plugin\views\filter\ColumnSelector->buildExposedForm() (line 146 of modules/contrib/flexible_views/src/Plugin/views/filter/ColumnSelector.php).
* Notice: Trying to access array offset on value of type null in Drupal\flexible_views\Plugin\views\filter\ColumnSelector->buildExposedForm() (line 146 of modules/contrib/flexible_views/src/Plugin/views/filter/ColumnSelector.php).
* Notice: Undefined index: field_campaign_status in Drupal\flexible_views\Plugin\views\filter\ColumnSelector->buildExposedForm() (line 146 of modules/contrib/flexible_views/src/Plugin/views/filter/ColumnSelector.php).
* Notice: Trying to access array offset on value of type null in Drupal\flexible_views\Plugin\views\filter\ColumnSelector->buildExposedForm() (line 146 of modules/contrib/flexible_views/src/Plugin/views/filter/ColumnSelector.php).
* Notice: Undefined index: field_brandcare_status in template_preprocess_views_view_flexible_table() (line 223 of modules/contrib/flexible_views/flexible_views.theme.inc).
* Notice: Trying to access array offset on value of type null in template_preprocess_views_view_flexible_table() (line 223 of modules/contrib/flexible_views/flexible_views.theme.inc).
* Notice: Undefined index: field_campaign_status in template_preprocess_views_view_flexible_table() (line 223 of modules/contrib/flexible_views/flexible_views.theme.inc).
* Notice: Trying to access array offset on value of type null in template_preprocess_views_view_flexible_table() (line 223 of modules/contrib/flexible_views/flexible_views.theme.inc).

Steps to reproduce

  1. Enable Views Conditional (8.x-1.4)
  2. Create/edit a view (page) and add there a field: Views Conditional. In this example case the field depends on the Content type, and will cause either field_brandcare_status or field_campaign_status to be used.
  3. Visit the view page and you'll see the aforementioned Notices.

Proposed resolution

Check if the field exists. In ColumnSelector.php:
if (isset($fields[$field_name]['default_visible']) && $fields[$field_name]['default_visible']) { ...

In flexible_views.theme.inc:

(isset($options['info'][$field]) ?
        $options['info'][$field]['default_visible'] || $always_visible:
        $always_visible);

...

Remaining tasks

See the patch if the changes are applicable.

User interface changes

API changes

Data model changes

Comments

mlahde created an issue. See original summary.

daveiano’s picture

Status: Active » Needs review

Thank you for the issue report and for providing a patch! I will have a look at it within the next weeks, but tests are already looking good.

daveiano’s picture

Issue tags: +2.0.4

  • daveiano committed 668fcb8 on 2.x authored by mlahde
    Issue #3254305 by mlahde: Undefined index in case of Views Conditional
    
daveiano’s picture

Version: 2.0.3 » 2.x-dev
Status: Needs review » Fixed

Patch is tested and merged. I also added a check flexible_views.theme.inc:

-      if (!in_array($column, $column_order) && $options['info'][$column]['default_visible']) {
+      if (!in_array($column, $column_order) && isset($options['info'][$column]) && $options['info'][$column]['default_visible']) {

This triggered also a notice for me when using Views conditional. Will be included in the next 2.0.4 release.

Status: Fixed » Closed (fixed)

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