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
- Enable Views Conditional (8.x-1.4)
- 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.
- 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
| Comment | File | Size | Author |
|---|---|---|---|
| flexible-views-conditional-field-notice.patch | 1.39 KB | mlahde |
Comments
Comment #2
daveianoThank 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.
Comment #3
daveianoComment #5
daveianoPatch is tested and merged. I also added a check flexible_views.theme.inc:
This triggered also a notice for me when using Views conditional. Will be included in the next 2.0.4 release.