Problem/Motivation
We hardcoded length for TelephoneItem to 256. However TelephoneDefaultWidget doesn't set #maxlength in TelephoneDefaultWidget::formElement() which makes it be set to 128 (default for Drupal\Core\Render\Element\Tel).
Steps to reproduce
- Add a telephone field to a content type
- Inspect the field and verify maxlengh is 128
Proposed resolution
Set TelephoneDefaultWidget maxlength to 256
Remaining tasks
Code review
Commit
User interface changes
User can input all 256 chars
API changes
Added constant TelephoneItem::MAX_LENGTH=256 which is used for #maxlength
Data model changes
NA
Release notes snippet
NA
Screenshots
Before patch (via #44)

After patch (via #44)

| Comment | File | Size | Author |
|---|---|---|---|
| #63 | 2862922-63.patch | 3.52 KB | smustgrave |
| #63 | interdiff-60-63.txt | 1.32 KB | smustgrave |
| #55 | 2862922-55.patch | 3.26 KB | pooja saraah |
| #53 | After Patch.png | 145.44 KB | prasanth_kp |
| #53 | Before Patch.png | 152.27 KB | prasanth_kp |
Issue fork drupal-2862922
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 2862922-set-maxlength-for
changes, plain diff MR !2564
Comments
Comment #2
zaporylieThe easiest way of solving this issue will be hardcoding #maxlength in form element.
Comment #3
zaporylieHowever I'd pleased if we go for more generic solution.
Comment #5
zaporylieOk, second approach clearly fails and I'm not sure if extending field schema with no interface is a good decision. Make no sense to me. So let's stay with first option (#2) for now.
Comment #6
zaporylieWrong tag
Comment #13
NitinLama commentedComment #14
NitinLama commentedHardcoding #maxlength in form element seems like a better option.
Comment #16
NitinLama commentedCan someone help me out with the failed test case on the above patch of comment #15 ?
Comment #17
NitinLama commentedComment #18
NitinLama commentedHardcoding #maxlength in form element seems like a better option. Drupal 9.0.x
Comment #19
tanubansal commentedTested #18 on 9.1, max length has been hard coded
RTBC + 1
Comment #21
abhijith s commentedApplied patch #18 on 9.2.x and it works fine. The max length in form element is set to 256 after patch.Adding screenshots.
Before patch:

After patch:

I'm moving it to RTBC
Comment #22
abhijith s commentedComment #23
alexpottLet's add a constant \Drupal\telephone\Plugin\Field\FieldType\TelephoneItem::MAX_LENGTH so this is maintained in a single place.
Comment #24
NitinLama commentedIGNORE
Comment #25
NitinLama commentedAs per #23
Comment #26
NitinLama commentedComment #28
NitinLama commentedComment #31
vikashsoni commentedApplied #18 patch applied successfully and looks good for me
Thanks for the patch
for ref sharing screenshot....
Comment #32
ranjith_kumar_k_u commentedComment #33
murilohp commentedJust a minor suggestion here, IMHO I think we should use
TelephoneItem::MAX_LENGTHdirectly, I mean, the constant is already public and this way we avoid calling the function and then the variable. What do you think?That's it from my side, thanks for the patch!
Comment #35
smustgrave commentedI agree with #34 so this should be rerolled with that suggestion.
Also needs tests
Comment #38
rakhi soni commentedKindly review patch for version 9.5x,,
Comment #39
smustgrave commentedCan you please provide an interdiff so we can see the changes
Comment #40
bnjmnm#38 is literally the same patch as #32
So
Also remove "needs reroll" tag, I ran patch #32 on 9.5.x. It applies and tests pass, which confirms no reroll is necessary. A reroll is only needed if the patch doesn't apply to the current dev branch. Patches created during earlier dev branches are often able to apply to later ones. A reroll is typically only necessary if they specifically target lines that have changed since the patch was created.
Comment #41
smustgrave commentedMoving to NW for the test cases
Comment #42
smustgrave commentedStarting at #32
Addressed #33 and add a simple test line
Comment #44
sonam.chaturvedi commentedVerified and tested patch #42. Patch applied successfully on 9.5.x-dev.
Test Steps:
1. Patch #42 includes #33 (to use TelephoneItem::MAX_LENGTH)
2. Apply patch
3. Check #maxlength for TelephoneDefaultWidget is now set to 256.
Test Result:
#maxlength for TelephoneDefaultWidget is now set to 256.
Moving to RTBC
Before patch:

After patch:

Comment #45
quietone commentedA test was added in #42 and there has been no review of that. Setting to NW for a code review.
I see that screenshots were added for that on 23 December 2021 at 17:54 in #31 for a 1 year old patch. That patch, #17, was failing tests on 17 Dec 2020. Therefore credit has been removed.
Comment #46
smustgrave commented@quietone updated issue summary with most recent screenshots in #44.
Moving to NR for the code review portion.
Comment #47
Manibharathi E R commentedPatch #42 Tested and Applied successfully on Drupal 9.5.x.
Steps to Reproduce:
1. Enable telephone module in the Drupal.
2. Create new field with the Telephone number field type.
3. Try to create the content inspect and check the max-length attribute of the Telephone number field.
4. Apply the patch.
Test Results:
After applying the patch. Field max-length is updated into the 256.
Comment #49
kristen polTriaging for bugsmash so tagging.
@Manibharathi E R Please read comments #45 and #46. The manual testing is complete and the test code just needs code review so there was no need to retest. Thanks.
Comment #50
kristen polI have reviewed the test code in #42 and it appears correct and the test-only patch failed as expected.
Marking RTBC based on the following. Thanks, everyone!
Comment #51
alexpottThe const should have documentation and we should also use this in \Drupal\telephone\Plugin\Field\FieldType\TelephoneItem::schema() and \Drupal\telephone\Plugin\Field\FieldType\TelephoneItem::getConstraints() - here we can remove the $max_length variable completely.
Comment #52
smustgrave commentedAddressed points in #51
Comment #53
prasanth_kp commented#52 applied successfully on Drupal 10.1.x-dev, Thanks for the patch
Comment #54
danielvezaNit: I think we can remove the "With the default" comment. I don't think that's relevant to the const.
I think this should use the const as well.
Does it fail when an int is passed? If is does we should just cast it to a string
Comment #55
pooja saraah commentedAddressed the comment #54 point 1.
point 2 need to be addressed
Could not apply patch #52 in Drupal 10.1.x
Attached patch against Drupal 10.1.x
Comment #56
ritesh k commentedComment #57
ritesh k commentedPatch #55 is working fine, please check screenshot attached for reference.
Comment #58
ritesh k commentedCheck the screenshot for after patch #55 applied
Comment #59
danielveza#54 still needs addressing. Recommend to use the patch from #52
Comment #60
danielvezaAddressed the feedback in #54, this patch is based on #52. Since the feedback was mine I'm leaving it in needs review rather than RTBC.
Comment #61
ameymudras commentedTested on Drupal 10.1.x and PHP 8.1
- Title and issue summary are clear
- Was able to reproduce the issue using the steps provided
- Patch applies cleanly and fixes the issue
- No coding standard issues detected
- Did a code review and no issues were identified
- Tests pass
Marking as RTBC, not adding screenshots since they have already provided earlier and not much has changed since
Comment #62
bnjmnmWhile the purpose of adding this const was to make this value available to the telephone widget, this description is not accurate. It is used for more than that.
If it described it is the max length for storage, that should be fine since it's true within this class. How it's used by other classes invoking it is up to them.
No need to escape the single quotes for the input[name] selector just use double.
Comment #63
smustgrave commentedTried to address points in #62
Comment #64
andypostI think it ready, update IS
Comment #66
larowlanChanged on commit, I didn't feel it was ok to knock this back for the third time on a comment for a constant.
Removing issue credit for screenshots that were added when we already had screenshots
Adding issue credit for those who reviewed the code that had an outcome on the final result
Committed to 10.1.x, backported to 10.0.x and 9.5.x as the risk of disruption is low.