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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

aadityawalawalkar’s picture

Please find the patch to resolve this issue.

aadityawalawalkar’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, RequiredCountryfield-1907918-1.patch, failed testing.

jnettik’s picture

Tested patch against 2.1 and dev, couldn't get it to apply on either branch. However I added the code manually and that works.

Alan D.’s picture

Version: 7.x-2.1 » 7.x-2.x-dev

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

aadityawalawalkar’s picture

Status: Needs work » Needs review
FileSize
1.13 KB

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

jnettik’s picture

Status: Needs review » Reviewed & tested by the community

Patch works great for me. Thank you!

geek-merlin’s picture

Alan D.’s picture

Thanks everyone. Congrats Aaditya, your first accredited commit :)

Committed with one minor change:

-    $required = isset($element['#required']) ? $element['#required'] : FALSE;
+    $required = !empty($element['#required']);
Alan D.’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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