TypeError: Argument 1 passed to Drupal\ui_patterns_views\Plugin\views\row\Pattern::isFieldVisible()

Created on 25 February 2023, over 1 year ago
Updated 9 February 2024, 9 months ago

Problem/Motivation

TypeError: Argument 1 passed to Drupal\ui_patterns_views\Plugin\views\row\Pattern::isFieldVisible() must be an instance of Drupal\views\Plugin\views\field\FieldPluginBase, null given, called in /var/www/html/docroot/modules/contrib/ui_patterns/modules/ui_patterns_views/ui_patterns_views.module on line 42 in Drupal\ui_patterns_views\Plugin\views\row\Pattern->isFieldVisible() (line 145 of /var/www/html/docroot/modules/contrib/ui_patterns/modules/ui_patterns_views/src/Plugin/views/row/Pattern.php)

Steps to reproduce

1. Enable "UI Patterns Views" module.
2. Select pattern in existing View.
3. Configure field mapping.

Proposed resolution

1. Add validation to check if $field and $field_output are not empty.

🐛 Bug report
Status

Fixed

Version

1.0

Component

UI Patterns Views

Created by

🇮🇳India Shashwat Purav Mumbai

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

Merge Requests

Comments & Activities

  • Issue created by @Shashwat Purav
  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • 🇮🇳India Shashwat Purav Mumbai

    Added patch to add validation to check if $field and $field_output are not empty.

  • Status changed to Postponed: needs info over 1 year ago
  • 🇫🇷France Grimreaper France 🇫🇷

    Hello,

    To understand the condition of the error, can you share your pattern YAML and Twig template please?

  • Status changed to Needs review about 1 year ago
  • 🇧🇪Belgium Steven Dullaert

    We had this same issue, and after quite a bit of detective work I've figured out what caused it (in our case).

    Our situation:
    We have a "Content select" view (which is used by an entity browser to add page teasers in a layout builder block via entity reference field). This view has a display, lets call it "Display A", that uses a 'Card' pattern for it's row display, and has the following fields, mapped to the pattern.

    • Content: Entity browser bulk select form
    • Content: Featured image (field_featured_image)
    • Content: Title
    • Content: Teaser

    After a colleague recently added a new display "Display B" to this view, our initial Display A no longer worked. When the entity browser modal was opened, the above error would be shown in the modal.

    Display B is a copy of Display A, but includes a new field, Content: Image (field_image) which was specifically added only to this display, because it lists a content type that doesn't use field_featured_image.

    However, when checking with xdebug, if found out that when Display A was displayed, the foreach at line 42 of ui_patterns/modules/ui_patterns_views/ui_patterns_views.module also included field_image as one of the fields. Since that field does not exist on this display, which results in the error.

    However, reviewing the pattern mapping of the row display via the Views UI showed nothing wrong. There was no mention of field_image, or any mapping for it. And it wasn't mentioned in the Default display either.

    So what was wrong? It took a while to figure out, but this is where the problem lies:

    When the new display was created, and the new field was added to it, my colleague mapped field_image to a region in the pattern in the settings of the Pattern row display. However, he did not set the row display itself to the "this display override", so the mapping of field_image to the pattern region was saved for "All displays".

    Visually, in views UI, each display's row settings seem fine (because in Display A, field_image is not show as an option to map to the pattern), but the mapping still exists for that display because it was saved to the defaults for the whole view.

    So to reproduce:

    1. Create content type A with field X
    2. Create content type B with field X and Y
    3. Create a view.
    4. Make a display, that lists content type A, and set it rows style to pattern, and map field X to one of the regions in the settings.
    5. Clone the display, make it list content type B, add field Y as an override for that display's fields. Go to the row style settings, and map field Y to one of the regions of the patterns. (Make sure not to make that an override, but keep it for all displays"
    6. Visit the first view, it should throw the error.

    The patch in #2 fixes the error preventing the view from being displayed, but will still throw the following warning:

    Warning: Undefined array key "field_image" in template_preprocess_pattern_views_row() (line 44 of modules/contrib/ui_patterns/modules/ui_patterns_views/ui_patterns_views.module).

  • Status changed to Needs work about 1 year ago
  • First commit to issue fork.
  • Status changed to Needs review about 1 year ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    86 pass
  • 🇮🇳India RiyaDongre

    Modified the patch and added a condition to see if the field is available in the current display. Please review.

  • 🇮🇳India RiyaDongre

    Here's adding an interdiff for your reference, that contains the condition applied in the patch.

  • Assigned to Grimreaper
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.1 + Environment: PHP 8.1 & MySQL 5.7
    last update 10 months ago
    CI error
  • 🇫🇷France Grimreaper France 🇫🇷

    @steven.d thanks a lot for the detailed steps to reproduce.

    Confirming I am able to reproduce and that the proposed fix avoid the fatal error but a warning remains so I have simplified the check and made a PR.

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.1 + Environment: PHP 8.1 & MySQL 5.7
    last update 10 months ago
    82 pass, 4 fail
  • Issue was unassigned.
  • Status changed to Fixed 10 months ago
  • 🇫🇷France Grimreaper France 🇫🇷
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024