I'm building kind of custom voting case with two nodes. Case node and Vote node. Vote node has Entity Reference field, which is select type widget and get populated via Views Entity Reference display.
Target type: node
Entity Selection mode: Views: Filter by entity reference view
I installed Entity Reference Count module and created field in Case node, but do not have any fields to be checked for count operations.
I resaved all existing nodes (Case and Vote nodes), but still no difference - can not select fields to be counted. Checked database - relations are set correctly, but particular count field stays on 0. On Entity Reference Count field settings the only trace of this module is the following text:
"There are no entity reference fields to count...."
Are there specific requirements for widgets in Entity reference field, to make this module work correctly?
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | entityreference_count-n1851094-7.patch | 2.81 KB | damienmckenna |
Comments
Comment #1
j2b commentedI experimentally added another Entity Reference field to Case node, and the first one (formerly added to Case node) appeared in Entity Reference Count field options. But only one.
Then I deleted all Votes and Count and Reference fields, and recreated it from scratch, even changing widgets of Entity reference field to Select list. No options came on at all after this.
Comment #2
rolfmeijer commentedI guess the problem lies in the fact that if you use “Views: Filter by an entity reference view” as Modus for the Entity Selection of the Entity Reference Field it won’t work. If you change this modus to be “Simple (with optional filter by bundle)” and than select the appropriate bundle, this field will appear in the Entity reference count-field.
Apparently it needs the bundle-information to be able to target the proper fields.
Comment #3
tobik999 commentedI got the same problem, and I am also using a view as entity selection mode. But I also changed one content type to use the simple mode as selector, but reference count number stays 0
Comment #4
damienmckennaThere are a few RTBC patches in the issue queue that should help with the counting, but it seems that there's an undocumented requirement that the "simple" reference field be used.
Comment #5
damienmckennaClosed a duplicate: #2393787: Not working with entity reference views
Comment #6
damienmckennaComment #7
damienmckennaThis adds a note to the README.txt and to the field instance settings form, plus it updates entityreference_count_field_options() to only look for the "Simple" fields.
Comment #8
damienmckennaThis ends up being a UI issue, not just documentation.
Comment #10
WorldFallz commentedCommitted this patch and updated the project page. Also created a new issue for resolving this limitation:#2667940: make it work with "views" based entityreference fields.
Comment #11
WorldFallz commentedComment #12
WorldFallz commentedTurns out this patch causes the fields to disappear again.
In this check, $field_type['settings']['handler_settings']['target_bundles'][$bundle] is the current bundle of the content type where the entityreference_count field is, not where the entityreference field is, so of course, it will fail and no field will show up. Also affects #2243165: improve performance which has the same logic.
Comment #13
damienmckennaMaybe time to start adding tests to define & confirm the expected behavior?
Comment #14
WorldFallz commentedDefinitely on my @todo list. Just trying to get it working first.
I'm actually not sure what that if-clause is supposed to be testing for in all honesty however. afaict, the only thing that matters is that it is a 'base' entityreference field (as opposed to the views style er field).
if you could explain the logic of that if it would help me figure out where the issue is.
In the meantime, the patch i have at #2243165: improve performance works (it just removes the additional check beyond 'base').
Comment #15
WorldFallz commentedThis has been fixed as of the improve performance issue. If you feel we're missing something due to removing the malfunctioning if, feel free to re-open or open a new issue for whatever additional logic you think we need. Thanks!