Hello guilopes,
after the last great improvement I had some further problems using the module for other entity types than "node". Furthermore the general problem existed that the "- Any -" selection appeared even if the field was set required, which is agains Drupal standards for radio buttons and hard to understand for users logically.
I fixed the problems (selected target id was not saved correctly) and added a check to add the "- Any -" option only if the field is optional.
Some explanations for you:
- The fixes at "#delta" were required to make it work correctly.
- We're now using "array_pop" instead of [0] because the index of the selected value may be different
- $delta is being counted dynamically now
- entityreference_rendered_widget_attach_fields() needed a further parameter "instance" to detect if the field instace is marked required
- $entity_type was renamed to $target_entity_type to make it more clear that not the parent entity is meant with this variable but the target entity (that was a bit confusing for me)
I've tested the result on several pages and it works great. Thank you for your great work at this module
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | entity selection views.PNG | 16.9 KB | anybody |
| #1 | several_improvements_and_entity_type_compatibility-2504437-1.patch | 13.02 KB | anybody |
Comments
Comment #1
anybodyPatch attached :)
Comment #2
anybodyHoping for your feedback now. If everything is okay it would be cool to see this in a future .dev release.
Comment #3
anybodyI just found a bug in the patch. I'll work on it and provide a new one when it's fixed!
Comment #4
anybodyAs I finally found out and now wrote to the maintainer of the module, there is a more easy and built-in functionality in entity_reference field.
If you use the radio widget you will find an "Entity Selection" fieldset in the fields settings where you can switch to "Views":

In the view you can use every field you'd like to with maximum flexiblity. For example in my case I used an image uploaded to an image field of the entity.
So I no more required this module. Perhaps that's also a good solution for your case?
It would be cool to have that information as alternative on the module page of this module. This will prevent people from having other issues and doesn't require an extra module.
Comment #5
guilopes commented