- Issue created by @kaszarobert
- Status changed to Needs review
26 days ago 9:43am 7 May 2024 - πΈπ°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
andHotels and restaurants
etc. individually as mentioned in the issue summary), instead of the whole built output (so not for the full outputWorkshop, 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 1:48pm 13 May 2024 - π³π±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.