Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Views: In "Unformatted list" format, Row classes don't render field tokens #5116

Open
bugfolder opened this issue Jun 14, 2021 · 9 comments
Open

Comments

@bugfolder
Copy link

bugfolder commented Jun 14, 2021

Description of the bug

In a View display as Unformatted list, one of the possible settings is "Row class", whose instructions say

You may use field tokens from as per the "Replacement patterns" used in "Rewrite the output of this field" for all fields.

The problem is that most of the tokens listed in "Replacement patterns" do not work for most fields.

Steps To Reproduce

To see the problem, on a basic Backdrop site (with Post content type predefined),

  1. Create a few Posts with images.
  2. Create a View with:
  • Format: Unformatted list
  • Show: Fields
  1. Add the "Content:image" field to the View. This will create the following tokens in the field's Replacement values:
  • [field_image]
  • [field_image-fid]
  • [field_image-alt]
  • [field_image-title]
  • [field_image-width]
  • [field_image-height]
  1. Go back to the Settings of the Unformatted list, and in "Row Class" enter some of these tokens.
  2. Save the View and examine its HTML. Or, more easily, check "Auto preview" and then examine the HTML on the View edit page.

You will see that most of these tokens are not replaced in the row classes with their appropriate values; instead they show in in the row classes nearly verbatim (without the square brackets).

The attached View config file demonstrates the example.

If you add fields to the content type, add the fields to the View, and attempt to use their tokens, they similarly do not render. There's nothing special about the image field; I'm just using that as an example because it's already present in the post content type.

Actual behavior

Some tokens work (e.g., [title]), but many field tokens do not. Instead of rendering their value, they are rendered as token text without the square brackets.

Expected behavior

All field tokens should be rendered as their values in the "Row class" field. This works on D7 Some tokens work on D7 but not on Backdrop; others don't work on both D7 and Backdrop, even though they are listed in "Replacement patterns" for the fields.

Additional information

Add any other information that could help, such as:

  • Backdrop CMS version: 1.19.1.

views.view.row_classes_test.json.txt

@indigoxela
Copy link
Member

@bugfolder I didn't test yet, but for clarification: it works in D7 if entity_token is installed? Also: would it work in B if entity_token is installed, or is this completely unrelated to that?

@bugfolder
Copy link
Author

I think this is unrelated to entity_token (which doesn't exist by that name on D7). The field tokens are presented as possible replacement patterns in Views even with no token-related modules installed (in D7 or B).

However, on further investigation, I've found that most of the field tokens do NOT work in "Row classes" even in D7. In fact, the only one I've found that does is "List (integer)", which requires the D7 List module to be enabled. (This was, in fact, the use case that led me to discover it; I upgraded a D7 site and found that the row class was broken.)

So the 'field_image-fid] token doesn't work on D7 or B. But if you create a "List (integer)" field on the D7 site, add the field to the view, then use its token in a row class, it will work on D7 but not B. Many (most?) fields won't work on either.

@indigoxela
Copy link
Member

Hm... I just got it working in Backdrop.

  1. Created a list field (integer) in a content type
  2. Created a view of that type
  3. Added the list field, display the key, not the value
  4. Added an override for that field: foobar-[field_integer_list]
  5. Successfully used the row class with [field_integer_list], that resulted in "foobar-27"

I'm not 100% sure if every step of the above is necessary. And I'm also not sure if this works as intended...

@olafgrabienski
Copy link

I've found that most of the field tokens do NOT work in "Row classes" even in D7

I've quickly tested most Backdrop core field types. Apart from the types mentioned above, the following work without problem:

  • Boolean
  • List (text)
  • Short text
  • Title

Actually, the last has a problem if it's linked which is the default field configuration in Views. Similarly, many other field types work generally, but the output with default field configuration isn't really helpful. Examples:

  • Body: pThis-is-the-body-p
  • Date: span-classdate-display-rangespan-classdate-display-startTuesday-June-29-2021---600pm-span-to-span-classdate-display-endWednesday-June-30-2021---600pm-span-span
  • Email: a-hrefmailtoinfoexamplecominfoexamplecom-a

@klonos
Copy link
Member

klonos commented Jun 14, 2021

...most of the field tokens do NOT work in "Row classes" even in D7

The initial report claims that "This works on D7, not on Backdrop.". @bugfolder can you please edit it, to have it reflect what is a fact after recent comments/investigation?

...many other field types work generally, but the output with default field configuration isn't really helpful.

Yeah, it is sad, but we are heavily behind on Views 7.x crossports. Whatever solution we come up with here, I would like us to first try and bring Backdrop core Views in parity with Views 7.x, then see if things are as broken. Otherwise, I'd like us to at least make sure to compare any behavior we see in Backdrop to how Views 7.x works (and thank you all for already doing that).

In General, I'm really keen to bringing Backdrop core up to date with D7 crossports, and then moving on to Views 7.x crossports (and other 7.x contrib that has been merged into Backdrop core, but core and Views should be top priority).

@klonos
Copy link
Member

klonos commented Jun 14, 2021

... https://www.drupal.org/project/views/issues/1414592 seems related (or another manifestation of the same issue). Can anyone please confirm?

@bugfolder
Copy link
Author

The initial report claims that "This works on D7, not on Backdrop."... can you please edit it

Updated.

@docwilmot
Copy link
Contributor

Confirmed this for image fields.

@docwilmot
Copy link
Contributor

Also confirmed it also doesnt work in D7. If you rearrange fields, youll find that only the actual field value is available to other fileds. So if you have the Content: title field below the Content: image field, only the [field_image] token is availablt to the title field as a replacement, whereas the others, [field_image-alt], [field_image-title] etc are not only available to the image field itself. I suspect then that they wont be available to the Row classes textfield either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants