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?

Comments

j2b’s picture

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

rolfmeijer’s picture

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

tobik999’s picture

I 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

damienmckenna’s picture

Title: No fields to select to be counted » Module requires "simple" reference fields
Component: Code » Documentation
Category: Support request » Bug report
Issue summary: View changes
Priority: Major » Normal

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

damienmckenna’s picture

damienmckenna’s picture

damienmckenna’s picture

Status: Active » Needs review
StatusFileSize
new2.81 KB

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

damienmckenna’s picture

Component: Documentation » User interface

This ends up being a UI issue, not just documentation.

WorldFallz’s picture

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

WorldFallz’s picture

Status: Needs review » Fixed
WorldFallz’s picture

Status: Fixed » Needs work

Turns out this patch causes the fields to disappear again.

 if ($field_type['type'] == 'entityreference' && isset($field_type['settings']['handler_settings']['target_bundles'][$bundle]) && $field_type['settings']['handler_settings']['target_bundles'][$bundle] === $bundle && $field_type['settings']['handler'] == 'base') {

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.

damienmckenna’s picture

Maybe time to start adding tests to define & confirm the expected behavior?

WorldFallz’s picture

Definitely 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').

WorldFallz’s picture

Status: Needs work » Fixed

This 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!

Status: Fixed » Closed (fixed)

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