0

I just want to count the number of field collections items in a row. I am working on a view. In the view I am able to show the field collection items value, but I do not want the value I just want to count number of items per row.

I am trying view aggregate but its showing sql errors.

1 Answer 1

1

While it may be possible with just using Views. I find it easier to do this type of 2-step logic in Drupal with additional information.

For example use Computed Field module to store an integer value in the field on node save for a custom computed field called number_of_fc_values or whatever you want to call it. You then just count the number of field collection items on save using PHP.

For example your PHP could look like the following for the computed value PHP field, this example API usage is taken from https://drupal.stackexchange.com/a/84282/3279

$node_with_fc = node_load($node->nid);
$items = field_get_items('node', $node_with_fc, 'NAME_OF_FC_FIELD');
return count($items);

Now in your View you simply add your number_of_fc_values field to the field values for the row display.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.