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

  1. Add a telephone field to a content type
  2. 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)
before patch

After patch (via #44)
after patch

CommentFileSizeAuthor
#63 2862922-63.patch3.52 KBsmustgrave
#63 interdiff-60-63.txt1.32 KBsmustgrave
#60 interdiff-52-60.txt1.57 KBdanielveza
#60 2862922-60.patch3.52 KBdanielveza
#58 after-patch.JPG126.43 KBritesh k
#57 before-patch.JPG136.7 KBritesh k
#55 reroll_diff_52-55.txt2.5 KBpooja saraah
#55 2862922-55.patch3.26 KBpooja saraah
#53 After Patch.png145.44 KBprasanth_kp
#53 Before Patch.png152.27 KBprasanth_kp
#52 2862922-52.patch3.29 KBsmustgrave
#52 interdiff-42-52.txt1.42 KBsmustgrave
#47 After-Patch-2862922-42.png490.62 KBManibharathi E R
#47 Before-Patch-2862922-42.png502.46 KBManibharathi E R
#44 after_patch42.png100.82 KBsonam.chaturvedi
#44 before_patch42.png87.24 KBsonam.chaturvedi
#42 2862922-42.patch2.15 KBsmustgrave
#42 2862922-42-tests-only.patch761 bytessmustgrave
#42 interdiff-32-42.txt1.65 KBsmustgrave
#38 Set-maxlength-for-TelephoneDefaultWidget-2862922-38.patch1.51 KBrakhi soni
#32 interdiff_28-32.txt1.09 KBranjith_kumar_k_u
#32 2862922-32.patch1.5 KBranjith_kumar_k_u
#31 2862922--after--patch--pic.png65.82 KBvikashsoni
#31 2862922--before--patch.png67.23 KBvikashsoni
#28 set-maxlength-2862922-27.patch1.5 KBNitinLama
#25 set-maxlength-2862922-24.patch1.5 KBNitinLama
#21 2862922-after.png59.78 KBabhijith s
#21 2862922-before.png61.83 KBabhijith s
#18 set-maxlength-2862922-18.patch713 bytesNitinLama
#14 set-maxlength-2862922-14.patch713 bytesNitinLama
#3 set_maxlength_for-2862922-3.patch2 KBzaporylie
#2 set_maxlength_for-2862922-2.patch707 byteszaporylie

Issue fork drupal-2862922

Command icon 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:

Comments

zaporylie created an issue. See original summary.

zaporylie’s picture

Status: Needs work » Needs review
StatusFileSize
new707 bytes

The easiest way of solving this issue will be hardcoding #maxlength in form element.

zaporylie’s picture

StatusFileSize
new2 KB

However I'd pleased if we go for more generic solution.

Status: Needs review » Needs work

The last submitted patch, 3: set_maxlength_for-2862922-3.patch, failed testing.

zaporylie’s picture

Status: Needs work » Needs review

Ok, 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.

zaporylie’s picture

Wrong tag

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

NitinLama’s picture

Assigned: Unassigned » NitinLama
Status: Needs review » Needs work
NitinLama’s picture

Assigned: NitinLama » Unassigned
Status: Needs work » Needs review
StatusFileSize
new713 bytes

Hardcoding #maxlength in form element seems like a better option.

Status: Needs review » Needs work

The last submitted patch, 14: set-maxlength-2862922-14.patch, failed testing. View results

NitinLama’s picture

Can someone help me out with the failed test case on the above patch of comment #15 ?

NitinLama’s picture

Assigned: Unassigned » NitinLama
NitinLama’s picture

Assigned: NitinLama » Unassigned
Status: Needs work » Needs review
StatusFileSize
new713 bytes

Hardcoding #maxlength in form element seems like a better option. Drupal 9.0.x

tanubansal’s picture

Tested #18 on 9.1, max length has been hard coded
RTBC + 1

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

abhijith s’s picture

StatusFileSize
new61.83 KB
new59.78 KB

Applied 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:
before

After patch:
after

I'm moving it to RTBC

abhijith s’s picture

Status: Needs review » Reviewed & tested by the community
alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Let's add a constant \Drupal\telephone\Plugin\Field\FieldType\TelephoneItem::MAX_LENGTH so this is maintained in a single place.

NitinLama’s picture

StatusFileSize
new1.5 KB

IGNORE

NitinLama’s picture

Assigned: Unassigned » NitinLama
Status: Needs work » Needs review
StatusFileSize
new1.5 KB

As per #23

NitinLama’s picture

Assigned: NitinLama » Unassigned

Status: Needs review » Needs work

The last submitted patch, 25: set-maxlength-2862922-24.patch, failed testing. View results

NitinLama’s picture

Assigned: Unassigned » NitinLama
Status: Needs work » Needs review
StatusFileSize
new1.5 KB

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

vikashsoni’s picture

StatusFileSize
new67.23 KB
new65.82 KB

Applied #18 patch applied successfully and looks good for me
Thanks for the patch
for ref sharing screenshot....

ranjith_kumar_k_u’s picture

StatusFileSize
new1.5 KB
new1.09 KB
murilohp’s picture

+++ b/core/modules/telephone/src/Plugin/Field/FieldWidget/TelephoneDefaultWidget.php
@@ -66,6 +67,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
+      '#maxlength' => TelephoneItem::getMax(),

Just a minor suggestion here, IMHO I think we should use TelephoneItem::MAX_LENGTH directly, 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!

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll, +Needs tests

I agree with #34 so this should be rerolled with that suggestion.

Also needs tests

rpayanm made their first commit to this issue’s fork.

rakhi soni’s picture

Assigned: NitinLama » Unassigned
Status: Needs work » Needs review
StatusFileSize
new1.51 KB

Kindly review patch for version 9.5x,,

smustgrave’s picture

Can you please provide an interdiff so we can see the changes

bnjmnm’s picture

Issue tags: -Needs reroll

#38 is literally the same patch as #32
So

  • It's an unnecessary patch adding noise to the issue
  • The feedback that got it switched "Needs Work" has not been addressed, so that work still needs to be done. Therefore, the status should still be "needs work"

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.

smustgrave’s picture

Status: Needs review » Needs work

Moving to NW for the test cases

smustgrave’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new1.65 KB
new761 bytes
new2.15 KB

Starting at #32

Addressed #33 and add a simple test line

The last submitted patch, 42: 2862922-42-tests-only.patch, failed testing. View results

sonam.chaturvedi’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new87.24 KB
new100.82 KB

Verified 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:
bef patch

After patch:
after patch

quietone’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs work

A 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.

smustgrave’s picture

Issue summary: View changes
Status: Needs work » Needs review

@quietone updated issue summary with most recent screenshots in #44.

Moving to NR for the code review portion.

Manibharathi E R’s picture

StatusFileSize
new502.46 KB
new490.62 KB

Patch #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.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

kristen pol’s picture

Issue tags: +Bug Smash Initiative

Triaging 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.

kristen pol’s picture

Status: Needs review » Reviewed & tested by the community

I 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!

  1. Title and issue summary are clear and accurate
  2. Has steps to reproduce
  3. Has embedded "before" and "after" screenshots from #44
  4. Metadata seems fine
  5. Patch applies cleanly
  6. No coding standard issues in test bot
  7. Code addresses issue and does not change unrelated things
  8. Tests have been added and pass
  9. Test-only patch fails
  10. Issue was reproducible
  11. Manual testing was successful per #44
alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/telephone/src/Plugin/Field/FieldType/TelephoneItem.php
@@ -21,6 +21,8 @@
+  const MAX_LENGTH = 256;
+

The 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.

smustgrave’s picture

Status: Needs work » Needs review
StatusFileSize
new1.42 KB
new3.29 KB

Addressed points in #51

prasanth_kp’s picture

StatusFileSize
new152.27 KB
new145.44 KB

#52 applied successfully on Drupal 10.1.x-dev, Thanks for the patch

danielveza’s picture

  1. +++ b/core/modules/telephone/src/Plugin/Field/FieldType/TelephoneItem.php
    @@ -22,6 +22,11 @@
    +   * Set the max length of the telephone widget. Without the default is 128.
    

    Nit: I think we can remove the "With the default" comment. I don't think that's relevant to the const.

  2. +++ b/core/modules/telephone/tests/src/Functional/TelephoneFieldTest.php
    @@ -89,6 +89,7 @@ protected function setUp(): void {
    +    $this->assertSession()->elementAttributeContains('css', 'input[name=\'field_telephone[0][value]\']', 'maxlength', '256');
    

    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

pooja saraah’s picture

StatusFileSize
new3.26 KB
new2.5 KB

Addressed 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

ritesh k’s picture

Assigned: Unassigned » ritesh k
ritesh k’s picture

Assigned: ritesh k » Unassigned
StatusFileSize
new136.7 KB

Patch #55 is working fine, please check screenshot attached for reference.

ritesh k’s picture

StatusFileSize
new126.43 KB

Check the screenshot for after patch #55 applied

danielveza’s picture

Status: Needs review » Needs work

#54 still needs addressing. Recommend to use the patch from #52

danielveza’s picture

Status: Needs work » Needs review
StatusFileSize
new3.52 KB
new1.57 KB

Addressed 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.

ameymudras’s picture

Status: Needs review » Reviewed & tested by the community

Tested 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

bnjmnm’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/telephone/src/Plugin/Field/FieldType/TelephoneItem.php
    @@ -22,6 +22,11 @@
    +   * Set the max length of the telephone widget.
    

    While 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.

  2. +++ b/core/modules/telephone/tests/src/Functional/TelephoneFieldTest.php
    @@ -89,6 +90,7 @@ protected function setUp(): void {
    +    $this->assertSession()->elementAttributeContains('css', 'input[name=\'field_telephone[0][value]\']', 'maxlength', TelephoneItem::MAX_LENGTH);
    

    No need to escape the single quotes for the input[name] selector just use double.

smustgrave’s picture

Status: Needs work » Needs review
StatusFileSize
new1.32 KB
new3.52 KB

Tried to address points in #62

andypost’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

I think it ready, update IS

  • larowlan committed e5d49f8 on 10.0.x
    Issue #2862922 by smustgrave, NitinLama, zaporylie, rpayanm, DanielVeza...
  • larowlan committed d5b4f00 on 10.1.x
    Issue #2862922 by smustgrave, NitinLama, zaporylie, rpayanm, DanielVeza...
  • larowlan committed b444887 on 9.5.x
    Issue #2862922 by smustgrave, NitinLama, zaporylie, rpayanm, DanielVeza...
larowlan’s picture

Version: 10.1.x-dev » 9.5.x-dev
Status: Reviewed & tested by the community » Fixed

Changed on commit, I didn't feel it was ok to knock this back for the third time on a comment for a constant.

diff --git a/core/modules/telephone/src/Plugin/Field/FieldType/TelephoneItem.php b/core/modules/telephone/src/Plugin/Field/FieldType/TelephoneItem.php
index 7e2ff790044..3cec358056e 100644
--- a/core/modules/telephone/src/Plugin/Field/FieldType/TelephoneItem.php
+++ b/core/modules/telephone/src/Plugin/Field/FieldType/TelephoneItem.php
@@ -23,7 +23,7 @@
 class TelephoneItem extends FieldItemBase {
 
   /**
-   * Default max length for telephone storage.
+   * The maximum length for a telephone value.
    */
   const MAX_LENGTH = 256;
 

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.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.