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.
When I add a country field to an entity with the "Countries by continent" widget, when I set the field to be required it doesn't carry through to the edit form. I'm able to create new content on the my site without filling in the country field though it should be required.
Comment | File | Size | Author |
---|---|---|---|
#6 | RequiredCountryfield-1907918-6.patch | 1.13 KB | aadityawalawalkar |
#1 | RequiredCountryfield-1907918-1.patch | 1.32 KB | aadityawalawalkar |
Comments
Comment #1
aadityawalawalkar CreditAttribution: aadityawalawalkar commentedPlease find the patch to resolve this issue.
Comment #2
aadityawalawalkar CreditAttribution: aadityawalawalkar commentedComment #4
jnettikTested patch against 2.1 and dev, couldn't get it to apply on either branch. However I added the code manually and that works.
Comment #5
Alan D. CreditAttribution: Alan D. commentedLooks like this is likely to be required as a non-type FAPI element is unlikely to be validated. Using the passed in base $element is great as this has already done the delta == 0 then enforce required logic, etc.
However, the patch should be done against the latest 7.x-2.x branch.
And being anal about the possibility of this throwing PHP warnings, can you use !empty($element['#required']) instead? This prevents a PHP notice if #required is not set. :)
Then with some manual testing, I can look at pushing this through fairly quickly.
Brownie points if you want to attempt some tests, but the lack of these would not prohibit this issue getting committed.
Comment #6
aadityawalawalkar CreditAttribution: aadityawalawalkar commentedI have corrected patch to avoid any PHP warning which may arise if "#required" key is not set.
Corrected patch for 7.x-1.x-dev version of Countries module.
Comment #7
jnettikPatch works great for me. Thank you!
Comment #8
geek-merlin#6: RequiredCountryfield-1907918-6.patch queued for re-testing.
Comment #9
Alan D. CreditAttribution: Alan D. commentedThanks everyone. Congrats Aaditya, your first accredited commit :)
Committed with one minor change:
Comment #10
Alan D. CreditAttribution: Alan D. commented