ui_patterns icon indicating copy to clipboard operation
ui_patterns copied to clipboard

Pattern::isFieldVisible returns false on valid mappings by using field instead of id

Open pvbergen opened this issue 3 years ago • 0 comments

Drupal\ui_patterns_views\Plugin\views\row\Pattern::isFieldVisible returns false on valid mappings. This is caused by using different identifiers for mapping and visiblity check.

Problem

  • ViewsRowSource::getSourceField uses DisplayHandlerBase::getFieldLabels, returning field labels keyes by id
  • Pattern::isFieldVisible passes FieldPluginBase::field to hasMappingDestination, meaning field name

These values are usually the same in views, but don't have to be. This can cause fields to not be passed to patterns.

How to reproduce

We had this bug with the field "Published on" provided by drupal/publication_date.

  1. Install ui_patterns_view and publication_date
  2. Create a view, inserting the field "Published on" twice or more.
  3. Check the view config: It will show different values for id and field on all but the first field plugin

Sample from a view config

fields: published_at: id: published_at table: node_field_data field: published_at published_at_1: id: published_at_1 table: node_field_data field: published_at published_at_2: id: published_at_2 table: node_field_data field: published_at

Solution

Pass field id to isFieldVisible along with field. See changes in the PR.

pvbergen avatar Dec 21 '21 07:12 pvbergen