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.
There is a UserName validator which is a part of the Drupal's user module but that cannot be used. That constraint validator always requires a value but we don't need that. Also, the validator works with different typed data whereas we will work with just strings.
Comment | File | Size | Author |
---|---|---|---|
#8 | add_username_validator-3077523-8.patch | 3.89 KB | yonas.legesse |
Comments
Comment #2
junkuncz CreditAttribution: junkuncz at Petend commentedWhat is the exact idea here?
Comment #3
prethiee CreditAttribution: prethiee as a volunteer and at Axelerant commentedI'm guessing here is to add some custom constraints, validating the username. I used this user_validate_name function from D7 as reference except for requiring username and length, cause I think that the length can be added in the FieldType. Attaching a patch, please take a look into it and let me know if it fits the requirements you're going for.
Comment #4
prethiee CreditAttribution: prethiee as a volunteer and at Axelerant commentedComment #5
prethiee CreditAttribution: prethiee as a volunteer and at Axelerant commentedComment #6
junkuncz CreditAttribution: junkuncz at Petend commentedHi @prethiee!
Your code looks good to me, and functionality is also fine.
The decision is up to @hussainweb to accept and commit is.
Cheers,
Bálint
Comment #7
hussainwebThanks @prethiee for the patch. I have a few comments below. Apart from that, I assume you took the violations right from the UserName validator?
Let's namespace this id. How about calling it `DoUsernameFormat`?
Extra space here
Extra space here
Extra space here
The indentation is incorrect.
Comment #8
yonas.legesse CreditAttribution: yonas.legesse at Axelerant commentedChanged plugin identifier and checked for indentations.
Comment #9
prethiee CreditAttribution: prethiee as a volunteer and at Axelerant commentedThanks for the patch @yonas.legesse, yeah @hussainweb I used D7's user_validate_name function as reference.
Comment #11
hussainwebThanks for all your work here.