I have a content type Player ('player') that has a nodereference count filed ('field_matches').
Then I have two content types Match Counter-Strike Scoure ('match_css') and Match Black Ops ('match_bo'), these two content types has the same nodereference field 'field_players'.
But there is a problem, when adding a 'match_bo' node, the count field in 'player' don't get updated but it does when I create a 'match_css' node.
I have made some debugging and what I discovered was in this piece of code
$all_fields = content_fields();
$nodereference_fields = array();
foreach ($all_fields as $field) {
if ($field['type_name'] == $node->type && $field['type'] == 'nodereference') {
$nodereference_fields[$field['field_name']] = $field;
}
}
and the problem is that $all_fields['field_players'] has the 'type_name' to 'match_css', but this field also exists for the content type 'match_bo', but that is not in this array. So that is why my above example does not work, because this if case will never be true for 'match_bo', even if it has a field that is a nodereference.
I am working on a patch for this to help you developers with this problem.
Comments
Comment #1
Scyther commentedThe problem was easy solved by making the changes that you can see below.
The other foreach in that function should be as it was before, because later on in the code, the variable 'type_name' is not important and it is never used.
I have tested this code with various amount of content types that has the same nodereference and so on. Now it works as it should be.
Comment #2
Scyther commentedComment #3
gilgabar commentedThanks for the report and the fix.
As a general rule of thumb never set the status as "reviewed and tested by the community" for your own patches. Set the status to "needs review". The idea is that someone else needs to look at it and confirm that your code is acceptable.
That said, I was able to replicate the problem and confirm that the fix works. It has been committed and will appear in a dev release soon.