- ๐ธ๐ฎSlovenia borutpiletic
I can confirm what #33 described. I have seen the same issue in a custom template where
{ content.field_link.0['#url_title'] }
was used and it resulted in a trimmed URL being shown. - ๐บ๐ธUnited States angrytoast Princeton, NJ
I can reproduce the issue with a fresh site install on 10.2 on the
standard
profile.Adding a link field to the default Article content type and then configuring it on the content type's default display view mode shows the 80 character trim regardless of if it is the "Link" or "Separate link text and URL" option. It looks like this is defined as such in the respective plugins:
<a href="https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/link/src/Plugin/Field/FieldFormatter/LinkFormatter.php#L79-87">LinkFormatter::defaultSettings</a>
<a href="https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/link/src/Plugin/Field/FieldFormatter/LinkSeparateFormatter.php#L28-34">LinkSeparateFormatter::defaultSettings</a>
Digging into git history, it looks like this was added way back in 2013 at the early stages of Drupal 8 development. The issue doesn't have any clear reasons on why 80 characters is the default: https://www.drupal.org/project/drupal/issues/1796316 โ
Back to the main topic: I agree that the default trim length causes more confusion than the good it does. This is especially relevant in REST views when you try to output a link, if your sample data doesn't result in a trim, it is hard to tell this will become a problem. I think removing it from the plugin defaults is a good idea.
- ๐ฎ๐ณIndia prashant.c Dharamshala
Prashant.c โ made their first commit to this issueโs fork.
- Merge request !6068Link field display defaults to trim at 80 chars, breaking longer plaintext URLs โ (Open) created by prashant.c
- Status changed to Needs review
12 months ago 3:21pm 8 January 2024 - ๐ฎ๐ณIndia prashant.c Dharamshala
1. The
trim_length
property is of integer typetrim_length: type: integer label: 'Trim link text length'
therefore default value is required in integer not string.
2. Assigned dafault value to
'trim_length' => 0
in
LinkFormatter.php
andLinkSeparateFormatter.php
3. Changed the
'#min' => 1
to'#min' => 0
.4. It solves the truncate issue and we can assign the 0 from the UI as well in the manage fields.
5. Raising the MR and attaching the patch as well for
11.x
Thanks
- Status changed to Needs work
11 months ago 7:03pm 8 January 2024 - ๐บ๐ธUnited States smustgrave
This kind of change will need test coverage.
- First commit to issue fork.
- Status changed to Needs review
10 months ago 2:19pm 13 February 2024 - ๐ฉ๐ชGermany lmoeni
I fixed the failing test and adjusted the link formatter test with an longer url and empty 'trim_length' value.
Can someone take a look at this? - ๐ฎ๐ณIndia divya.sejekan
Verified with the latest MR . In FE view the issue looks fixed and also the links redirect to correct page. Keeping it in Review state for further reviews
Testing steps:
1. Add Link type to any CT
2. Set the link display as separate link and text in display setings
3. Create a node and verify in FE - Status changed to RTBC
10 months ago 3:31pm 23 February 2024 - ๐บ๐ธUnited States smustgrave
I git blamed this all the way to #501434: Move Link/URL field type into core โ where it appears the 80 was brought in when link module was merged in. Didn't see any discussion around it.
Believe making the change makes sense
Verified that existing link fields are unaffected by the change so no upgrade path needed.
New fields it works.
- Status changed to Needs work
10 months ago 1:02pm 8 March 2024 - ๐ฌ๐งUnited Kingdom longwave UK
Added some questions on the MR. I think this change is a good idea, even better that it only changes new fields and not existing ones.
- ๐ฎ๐ณIndia keshav patel
Keshav Patel โ made their first commit to this issueโs fork.
- Status changed to Needs review
8 months ago 12:21pm 5 May 2024 - Status changed to RTBC
7 months ago 2:10pm 20 May 2024 - ๐บ๐ธUnited States smustgrave
Tested this out on a standard install of 11.x
Added a link field to the Article content type
Didn't do anything special in the field settings
Went to view display and see that the link is not trimmed.I git blamed the 80 trim all the way to #1796316: Convert Link/URL widgets / formatters to plugin system โ from 12 years ago and don't see any discussion around the use of 80 so believe the update should be fine and good quality of life improvement.
- Status changed to Needs review
7 months ago 10:59am 1 June 2024 - ๐ฌ๐งUnited Kingdom alexpott ๐ช๐บ๐
This only affect link fields when the plaintext option has been selected. I'm not sure that the 80 trim default is a bad default when you a displaying a link instead of plain text. I think the trim option should be disabled when you select plaintext because it is only in combination with the plaintext option that the trim option becomes destrcutive.
- ๐บ๐ธUnited States smustgrave
So is the current proposal
That 80 is left as is
If you check the two boxes like so
Then the trim should disappear?
- Status changed to RTBC
6 months ago 10:11am 10 June 2024 - ๐ฎ๐ณIndia onkararun
@smustgrave when i Tested this on a standard install of 11.x and added a link field to the basic content type and i didn't do anything in the field settings then i got trimmed url and when i did changes in the field settings link check the 'Url only' and 'Show URL as plain text' with trim at 80 chars, in that case i also got the trimmed url.
But alexpott when i tested the merge reuqest MR !6068 then i didn't get any trimmed url. And it's working fine. - Status changed to Needs work
6 months ago 11:33am 10 June 2024 - ๐ฌ๐งUnited Kingdom alexpott ๐ช๐บ๐
The problem here is we're dealing with with a formatter that does two very different things.
- One is display the link in an anchor tag. Here the trim makes sense because you are not breaking the link.
- The other is to display the link as raw text - here the trim makes no sense whatsoever because you are breaking the link.
HEAD currently prioritise displaying as an anchor tag and this change prioritises displaying as a raw text. I think we should make the settings make sense depending on how you've chosen to display the link (raw vs anchor).
- ๐บ๐ธUnited States mherchel Gainesville, FL, US
One is display the link in an anchor tag. Here the trim makes sense because you are not breaking the link.
I would argue that although the trim works within an anchor tag, it should definitely not be the default. On practically all sites I work on I have to modify this default (on each and every link field on each display mode). If we were implementing this new, there's no way we would choose to truncate by default (although it should still be an option)