Add possibility to trim the result string, not the individual field values when all referenced field values are displayed in the same row

Created on 7 May 2024, 26 days ago
Updated 13 May 2024, 20 days ago

Problem/Motivation

Steps to reproduce

1. make sure to have a multi value entity reference field for a node, for example Tags which is a reference field to the Tags taxonomy terms
2. create a "Test" node, and set these tags: "Workshop, Hotels and restaurants, Office, Shopping malls, Stores, Schools, Manufacturing, Wellness and fitness, Healthcare"
3. create a view listing nodes
4. add node's title and node's Tags field
5. don't check "Link label to the referenced entity"
6. for Tag's field check "Display all values in the same row"
7. and under Rewrite results, check "Trim this field to a maximum number of characters"
8. set "Maximum number of characters" as 6 for the sake of demonstration now

Now you see that the trim is not doing a trim on the result but on each individual term names:
Worksh, Hotels, Office, Shoppi, Stores, School, Manufa, Wellne, Health

If you go back and check "Trim only on a word boundary", the result will look like this:
, , Office, , Stores, , , ,

We would need an option to trim the final generated string. The common use case is product feeds where they specify that a string field should be max. 100 characters long. It would be awesome if "Maximum number of characters" should reflect to the final field output in case of multiple values.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

✨ Feature request
Status

Needs work

Version

11.0 πŸ”₯

Component
ViewsΒ  β†’

Last updated about 12 hours ago

Created by

πŸ‡ΈπŸ‡°Slovakia kaszarobert

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

Comments & Activities

  • Issue created by @kaszarobert
  • Status changed to Needs review 26 days ago
  • πŸ‡ΈπŸ‡°Slovakia kaszarobert

    One possible solution would be adding a new "Do trimming" option where by default the current behavior stays (as "During single element rendering") but users would be able to change that to "Only after all field values are rendered"

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Can you think of a use case though where this is needed for core vs maybe being in a contrib module?

  • πŸ‡ΈπŸ‡°Slovakia kaszarobert

    In recent years at our company I can tell that we use trim in views mostly for creating proper product feeds for Google Merchant Center (with the help of contrib modules Commerce and Views Data Export). There Google specifies the maximal length of each field. If we specify something longer, then it rejects to read the product from our feed and we cannot create marketing campaigns for it.

    Since Drupal Views module has a trimming option, these max. lengths can be set easily for single value fields, such as product title, SKU, or category. So no need for custom code to build a proper feed. Awesome. But as soon as we put there multi-value fields such as the mentioned Tags, Collection or Custom Labels, I received a ticket where they say "I set the character limit to 100 and it still doesn't trim the output, please fix it". I looked into how this works and as I wrote in the issue summary, for multi-value fields for example a 100 character limit is applied to each individual value (to Workshop and Hotels and restaurants etc. individually as mentioned in the issue summary), instead of the whole built output (so not for the full output Workshop, Hotels and restaurants, Office, Shopping malls, Stores, Schools, Manufacturing, Wellness and fitness, Healthcare). If a setting is called "Trim this field to a maximum number of characters", then people expect to trim the whole field output, not the invidual field values.

    As I saw, developing something like this in another module is challenging as most of the conditions and trimming logic are not something that could be easily altered or replaced as there are no hooks or Events. That's why we took this core patch approach and since I think I'm not the only one who could face this, I initiated this idea here.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Thanks for the explanation. Will let a sub-maintainer review and then determine next steps like

    schema update
    upgrade path
    tests
    change record

  • Status changed to Needs work 20 days ago
  • πŸ‡³πŸ‡±Netherlands Lendude Amsterdam

    This behaviour is not specific to trimming, rewriting the result to a link acts the same way, it works on individual results, not the end result.

    The way to work around this is by hiding the multi value field and then using it as a token in a second field (based in an ID field for example) and then trimming the value of the field where you are using the token.

    I am not in favour of adding more settings to the multiple value form. If we want to fix this in a way that doesn't require a workaround I'd be looking more to a single checkbox that does something like 'Apply all Rewrites to the concatenated values' and then we don't need to change this one functionality at a time.
    Not saying that would be easy, because I don't think it is, but that would not make the Views UI any more crowded than it needs to be.
    My 2cts.

Production build 0.69.0 2024