Problem/Motivation

Possibly a follow-up to #1709960: declare a maximum length for entity and bundle machine names, where entity bundle machine names limit length to 32 characters. Contact category will throw the following exception when longer than 32 characters.

Proposed resolution

Add a maxlength to machine_name.

User interface changes

Alter machine name field only allow 32 characters.

API changes

None.

Steps to Reproduce

  1. Enable the contact module
  2. At Home > Administration > Structure > Contact form categories > Add category (admin/structure/contact/add)
  3. Add a label with a very long value like "ABCDEFGHIJKLM NOPQRSTUVWXYZ abcdefghijklm nopqrstuvwxyz 1234567890 ABCDEFGHIJKLM NOPQRSTUVWXYZ abcdefghijklm nopqrstuvwxyz 1234567890 ABCDEFGHIJKLM NOPQRSTUVWXYZ abcdefghijklm nopqrstuvwxyz 1234567890 ABCDEFGHIJKLM NOPQRSTUVWXYZ abcdefghijklm nopqrstuvwxyz 1234567890 ABCDEFGHIJKLM NOPQRSTUVWXYZ abcdefghijklm nopqrstuvwxyz 1234567890 ABCDEFGHIJKLM NOPQRSTUVWXYZ abcdefghijklm nopqrstuvwxyz 1234567890".
  4. Add a sample value to the required recipients field like "webmaster@example.com"
  5. Click save
  6. Site will return the following exception.

Drupal\Core\Config\Entity\Exception\ConfigEntityIdLengthException: Attempt to create a bundle with an ID longer than 32 characters: abcdefghijklm_nopqrstuvwxyz_abcdabcdefghijklm_nopqrstuvwxyz_abcd. in Drupal\Core\Entity\Entity->preSave() (line 347 of core/lib/Drupal/Core/Entity/Entity.php).

Comments

bdone’s picture

Assigned: bdone » Unassigned
Status: Active » Needs review
StatusFileSize
new848 bytes
dawehner’s picture

Issue tags: +Needs tests

I guess we should better write a test?

berdir’s picture

Status: Needs review » Needs work
Issue tags: +Novice

Yes, adding a test should be easy, just try to create a contact category with string length of 32 (should work) and 33 (should not work, validation error).

bdone’s picture

Assigned: Unassigned » bdone
bdone’s picture

Status: Needs work » Needs review
StatusFileSize
new2.48 KB
new1.65 KB

here's a pass at adding max_length asserts.

bdone’s picture

forgot, but added, @berdir's recommendation for checking equal max_length.

berdir’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests

Looks good I think.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.x, thanks!

  • Commit 9826e24 on 8.x by catch:
    Issue #2244775 by bdone: Declare a maximum length for contact category...

Status: Fixed » Closed (fixed)

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