Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
When configuring the Views Link field formatter, the "Trim link text length" UI prompts you to "Leave blank to allow unlimited link text lengths." However, the field validation will not allow blank values.
Proposed resolution
looking at core/modules/link/src/Plugin/Field/FieldFormatter/LinkFormatter.php
$elements['trim_length'] = array(
'#type' => 'number',
'#title' => t('Trim link text length'),
'#field_suffix' => t('characters'),
'#default_value' => $this->getSetting('trim_length'),
'#min' => 1,
'#description' => t('Leave blank to allow unlimited link text lengths.'),
);
Suggestions that the 'min' value is at odds with the blank requirement?
Remaining tasks
Update the code so that a blank value doesn't trigger the validation routine.
User interface changes
None recommended
Comment | File | Size | Author |
---|---|---|---|
#4 | Screen Shot 2020-09-08 at 12.56.42 pm.png | 10.02 KB | pameeela |
Screen Shot 2016-10-22 at 6.02.33 PM.png | 28.29 KB | Screenack |
Comments
Comment #4
pameeela CreditAttribution: pameeela commentedJust tried to reproduce this. It does throw this error if you enter '0' in the field, which makes sense as you can't trim to 0. It works if you actually leave the field blank.